9 Replies - 860 Views - Last Post: 13 June 2011 - 07:48 AM Rate Topic: -----

#1 xenor   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 148
  • Joined: 23-September 09

Upload picture is not working

Posted 13 June 2011 - 06:47 AM

Here is my code:
<html>
<body>

<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>



<html>

<?php
$_FILES["file"]["tmp_name"]="upload_picutre/";

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file";
  }
?>



I don't know where is the problem.. any hints???

Is This A Good Question/Topic? 0
  • +

Replies To: Upload picture is not working

#2 Duckington   User is offline

  • D.I.C Addict

Reputation: 172
  • View blog
  • Posts: 615
  • Joined: 12-October 09

Re: Upload picture is not working

Posted 13 June 2011 - 06:57 AM

You didn't say how it wasn't working (what the problem was), but from my quick test of it, maybe you could try changing the PHP script to:

<?php
if(isset($_FILES['file']))
{

    $_FILES["file"]["tmp_name"]="upload_picture/";

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file";
  }

}
?>



Though this won't actually upload the file, as you're not telling it to, you are just echoing out the details of the file.

If you want to then actually upload the file to the directory you specified, you would have to add this in:

<?php
if(isset($_FILES['file']))
{

    $path = "upload_picture/";

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    move_uploaded_file($_FILES["file"]["tmp_name"], $path . $_FILES["file"]["name"]);
    }
  }
else
  {
  echo "Invalid file";
  }

}
?>



I haven't tested that though.

This post has been edited by Duckington: 13 June 2011 - 07:02 AM

Was This Post Helpful? 0
  • +
  • -

#3 xenor   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 148
  • Joined: 23-September 09

Re: Upload picture is not working

Posted 13 June 2011 - 07:01 AM

Well i can't find the uploaded file...do i need something to add for it.
Was This Post Helpful? 0
  • +
  • -

#4 Duckington   User is offline

  • D.I.C Addict

Reputation: 172
  • View blog
  • Posts: 615
  • Joined: 12-October 09

Re: Upload picture is not working

Posted 13 June 2011 - 07:03 AM

I just added that to my first post
Was This Post Helpful? 1
  • +
  • -

#5 xenor   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 148
  • Joined: 23-September 09

Re: Upload picture is not working

Posted 13 June 2011 - 07:05 AM

I get "Stored in: D:\xampp\tmp\phpF89C.tmp" ...And i can't find the image..i am also getting warnings


Quote

Warning: move_uploaded_file(upload_picture/database_denes.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\xampp\htdocs\upload_picture\upload_file.php on line 23

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\xampp\tmp\php819C.tmp' to 'upload_picture/database_denes.jpg' in D:\xampp\htdocs\upload_picture\upload_file.php on line 23

This post has been edited by xenor: 13 June 2011 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

#6 Duckington   User is offline

  • D.I.C Addict

Reputation: 172
  • View blog
  • Posts: 615
  • Joined: 12-October 09

Re: Upload picture is not working

Posted 13 June 2011 - 07:09 AM

Is the upload_picture folder in the same directory as this script?

This post has been edited by Duckington: 13 June 2011 - 07:13 AM

Was This Post Helpful? 0
  • +
  • -

#7 xenor   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 148
  • Joined: 23-September 09

Re: Upload picture is not working

Posted 13 June 2011 - 07:15 AM

View PostDuckington, on 13 June 2011 - 07:09 AM, said:

Is the upload_picture folder in the same directory as this script?

Yep, i am checking for server configurations to see if the uploads are enabled.


Didn't find anything, file uploading is turned on.

This post has been edited by xenor: 13 June 2011 - 07:18 AM

Was This Post Helpful? 0
  • +
  • -

#8 Duckington   User is offline

  • D.I.C Addict

Reputation: 172
  • View blog
  • Posts: 615
  • Joined: 12-October 09

Re: Upload picture is not working

Posted 13 June 2011 - 07:19 AM

It could also be a permission problem on the folder I suppose. But the code I posted works fine for me on my localhost.

The only time I get the same errors as you is if I specify a directory to upload to that doesn't exist.
Was This Post Helpful? 0
  • +
  • -

#9 xenor   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 148
  • Joined: 23-September 09

Re: Upload picture is not working

Posted 13 June 2011 - 07:20 AM

View PostDuckington, on 13 June 2011 - 07:19 AM, said:

It could also be a permission problem on the folder I suppose. But the code I posted works fine for me on my localhost.

The only time I get the same errors as you is if I specify a directory to upload to that doesn't exist.

Well i am using XAMPP on windows 7, i don't think is the permissions.
Was This Post Helpful? 0
  • +
  • -

#10 xenor   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 148
  • Joined: 23-September 09

Re: Upload picture is not working

Posted 13 June 2011 - 07:48 AM

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("sliki_upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],  $_FILES["file"]["name"]); 
	 
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>




Now Works :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1