Jump to content

Image Uploader Please Help!!


NickG21

Recommended Posts

Hey guys, I know there are plenty of posts on here for this but I cant figure itout, i've been plugging non-stop for hours.  i've tried 4 different tutorials to modify etc etc andstill i can't get this thing to upload an image at all.  it says its successful and the image never shows up in the directory.  any help would be absolutey fantastic.

thank you.

here's my code and the success on the page after it's passed through.

 

<tr><td>Image Name:</td><td><input type = "file" name ="file" id="file"></td></tr>

	if(isset($_POST['submit'])){

		if ((($_FILES["file"]["type"] == "image/gif")
		|| ($_FILES["file"]["type"] == "image/jpeg")
		|| ($_FILES["file"]["type"] == "image/pjpeg"))
		&& ($_FILES["file"]["size"] < 200000000))
		  {
		  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("images/" . $_FILES["file"]["name"]))
		      {
		      echo $_FILES["file"]["name"] . " already exists. ";
		      }
		    else
		      {
		      move_uploaded_file($_FILES["file"]["tmp_name"],
		      "images/" . $_FILES["file"]["name"]);
		      echo "Stored in: " . "images/" . $_FILES["file"]["name"];
		      }
		    }
		  }
		else
		  {
		  echo "Invalid file";
		  }

and here is the page after submission and success of an image named "2.jpg"

 

Upload: 2.jpg

Type: image/pjpeg

Size: 1301.08398438 Kb

Temp file: /tmp/phpQrLfn8

 

this isn't ever last bit of code there is also a query that is created from the informationd depending on everything being set etc.. and that works perfectly and inserts the proper values into the DB, i just can't figure out this image uploader.

Thanks again in advance!

Link to comment
https://forums.phpfreaks.com/topic/163390-image-uploader-please-help/
Share on other sites

It's likely a path or a permission problem. For debugging, add the following two lines of code immediately after your first opening <?php tag -

 

ini_set("display_errors", "1");
error_reporting(E_ALL);

 

And the code you have should test for the TRUE/FALSE value returned by move_uploaded_file() and only echo a success message if the value returned was TRUE.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.