Chrisj Posted October 6, 2014 Share Posted October 6, 2014 I don't know why this image upload code isn't uploading the image file to the uploads/ folder. Any help will be appreciated. $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); if ( $_FILES["file"]["size"] < 2000000 && in_array($extension, $allowedExts) ) { if ($_FILES["file"]["error"]!= 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { $length = 20; $randomString = substr(str_shuffle(md5(time())),0,$length); $newfilename = $randomString . "." . $extension; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newfilename ); $file_location = '<a href="http://www.--.com/upload/' . $newfilename . '">http://www.--.com/upload/' . $newfilename . '</a>'; } } else { echo "Invalid upload file"; } <form enctype="multipart/form-data" action="uploader.php"> <input type="file" name="file" id="file"> <input type="submit" name="submitted" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/291476-image-file-is-not-uploading/ Share on other sites More sharing options...
Chrisj Posted October 6, 2014 Author Share Posted October 6, 2014 Got it Quote Link to comment https://forums.phpfreaks.com/topic/291476-image-file-is-not-uploading/#findComment-1492897 Share on other sites More sharing options...
requinix Posted October 6, 2014 Share Posted October 6, 2014 Mind sharing? Quote Link to comment https://forums.phpfreaks.com/topic/291476-image-file-is-not-uploading/#findComment-1492901 Share on other sites More sharing options...
Chrisj Posted October 6, 2014 Author Share Posted October 6, 2014 This change now gets the image uploaded, however this code takes me to the next page. I'd like to figure out how to stay on the same page after upload. Any help will be appreciated. <form enctype="multipart/form-data" action="" method="POST"> <input type="file" name="file" id="file"> <input class="upload-input" type="hidden" name="form_submitted" value="yes" /> <input type="submit" value="submit" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/291476-image-file-is-not-uploading/#findComment-1492906 Share on other sites More sharing options...
requinix Posted October 6, 2014 Share Posted October 6, 2014 Without reloading the page, you mean? That's AJAX, which is simple to implement... except for doing file uploads. Which isn't actually AJAX but whatever. Find yourself a Javascript library that can do file uploads and implement that in your site. Your PHP doesn't have to change much except it shouldn't output HTML (not when it's handling the file upload). Quote Link to comment https://forums.phpfreaks.com/topic/291476-image-file-is-not-uploading/#findComment-1492907 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.