Solarpitch Posted May 12, 2007 Share Posted May 12, 2007 Hey, I am trying to implement the below script but no matter what file type I upload, it will not upload the file. I keep getting the error "Invalid File" Here's the code... ************************************** PHP if (($_FILES["userfile"]["type"] == "image/gif") || ($_FILES["userfile"]["type"] == "image/pjpeg") && ($_FILES["userfile"]["size"] < 20000)) { if ($_FILES["userfile"]["error"] > 0) { echo "Return Code: " . $_FILES["userfile"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["userfile"]["name"] . "<br />"; echo "Type: " . $_FILES["userfile"]["type"] . "<br />"; echo "Size: " . ($_FILES["userfile"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["userfile"]["tmp_name"] . "<br />"; if (file_exists("/user_images/" . $_FILES["userfile"]["name"])) { echo $_FILES["userfile"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["userfile"]["tmp_name"], "/user_images/" . $_FILES["userfile"]["name"]); echo "Stored in: " . "/user_images/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ************************************** HTML ... form1" enctype="multipart/form-data"....... <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <input name="userfile" type="file" id="menu_textbox" /> Just looking for a bit of help, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/ Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 how big is the file that gives the "Invalid file" error? Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251617 Share on other sites More sharing options...
Solarpitch Posted May 12, 2007 Author Share Posted May 12, 2007 160kb . . ive tried with a load of file sizes! Still no Joy ( Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251648 Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 Has to be less than 20000 for your script Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251650 Share on other sites More sharing options...
Solarpitch Posted May 12, 2007 Author Share Posted May 12, 2007 But even when I put the size to <2000000 it still seems to fail Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251666 Share on other sites More sharing options...
textbox Posted May 12, 2007 Share Posted May 12, 2007 Have you set up the correct permissions on the folder /user_images/?? Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251672 Share on other sites More sharing options...
Barand Posted May 13, 2007 Share Posted May 13, 2007 put this just before the code you posted to see what is in the $_FILES array echo '<pre>', print_r($_FILES, true), '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251850 Share on other sites More sharing options...
runnerjp Posted May 13, 2007 Share Posted May 13, 2007 if (($_FILES["userfile"]["type"] == "image/gif") || ($_FILES["userfile"]["type"] == "image/pjpeg") && ($_FILES["userfile"]["size"] < 20000)) try adding .jpg to it as well as i had the same problem with pjpeg if (($_FILES["userfile"]["type"] == "image/gif") || ($_FILES["userfile"]["type"] == "image/pjpeg") || ($_FILES["userfile"]["type"] == "image/jpeg") && ($_FILES["userfile"]["size"] < 20000)) Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251887 Share on other sites More sharing options...
Solarpitch Posted May 13, 2007 Author Share Posted May 13, 2007 Ah textbox . . . it seemed to have been the permissions on the folder alright! Thanks everyone for the help anyway! Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251891 Share on other sites More sharing options...
Barand Posted May 13, 2007 Share Posted May 13, 2007 Textbox certainly hit the nail on head Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251892 Share on other sites More sharing options...
textbox Posted May 13, 2007 Share Posted May 13, 2007 Well theres a first time for everything!! I know its one of the most common mistakes as its something some people dont really think about! Quote Link to comment https://forums.phpfreaks.com/topic/51104-problem-with-file-upload-script/#findComment-251977 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.