NickG21 Posted June 23, 2009 Share Posted June 23, 2009 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! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 23, 2009 Share Posted June 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
alco19357 Posted June 23, 2009 Share Posted June 23, 2009 before: move_uploaded_file('... chmod image directory to 777 chmod("images/", 0777); and after move_uploaded_file('... chmod image directory back to original permissions ie: chmod("images/", 0644); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.