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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.