Chrisj Posted September 26, 2014 Share Posted September 26, 2014 I've added this code (below) to a file called uploader.php (attached). When I simply open the corresponding html page, I see "Invalid upload file" in the top left corner of the page. When I remove this code from uploader.php the "Invalid upload file" disappears. Any ideas on how to resolve this will be appreciated. $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); // in case user named file ".JPG" etc.!!! if ( $_FILES["file"]["size"] < 200000 && 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 . '">' . $newfilename . '</a>'; } } else { echo "Invalid upload file"; } $description = $description . " \n " . $newfilename; Quote Link to comment https://forums.phpfreaks.com/topic/291289-invalid-upload-file-appears-and-then-disappears/ Share on other sites More sharing options...
ginerjm Posted September 26, 2014 Share Posted September 26, 2014 Do you have php error checking turned on so you might see any possible errors in this code? I'm guessing that (obviously) your if statement is failing so that means either you are specifying the upload file field name incorrectly or the size is > 200000. Try echoing out those values before you execute the test to confirm what you think is there. Quote Link to comment https://forums.phpfreaks.com/topic/291289-invalid-upload-file-appears-and-then-disappears/#findComment-1492141 Share on other sites More sharing options...
mac_gyver Posted September 26, 2014 Share Posted September 26, 2014 the code you have posted is for processing a form submission. you are seeing the invalid .... message because you are unconditionally running the code when the page is requested and none of the values being tested exist, resulting in a false value for the conditional test that causes the invalid ... message to be output. any form processing code needs to test if the expected form has been submitted before attempting to use any of the form data. you are also seeing the error message at the top-left of the page because you are not outputting it through the template system the script you are trying to use is using to produce the html pages. you cannot simply copy/paste together code without taking into account the methods being used by the code you are trying to modify. Quote Link to comment https://forums.phpfreaks.com/topic/291289-invalid-upload-file-appears-and-then-disappears/#findComment-1492147 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.