Solarpitch Posted June 2, 2007 Share Posted June 2, 2007 Hey Guys, Below is a snippet of my file upload script thats causing a problem. Everytime I try to upload a file it seems to fail and output the defined error of "The submitted file was invalid." The file I am submitting is a jpg, 760kb. The file name is "pict0001.jpg". The script seems to work fine for smaller files but anything past 500kb or so just seems to fail. Anyone any ideas why . . . cause I am stumpted! function generate_rand($l){ $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; srand((double)microtime()*1000000); for($i=0; $i<$l; $i++) { $rand.= $c[rand()%strlen($c)]; } return $rand; } $uploaddir = "user_images/"; $maxfilesize = 1048576; //1 megabyte $filename = $_FILES['userfile']['name']; $filesize = $_FILES['userfile']['size']; $filetmpname = $_FILES['userfile']['tmp_name']; $valid = array (".jpg",".gif",".png"); if ($filename) { $error = ""; if ($filesize == 0) { $error_file .= "The submitted file was invalid.<br />"; $execute = "no"; } $type = strtolower(strstr($filename, '.')); if (!in_array($type, $valid)) { $error_file .= "The submitted file was of invalid type.<br />"; $execute = "no"; } if ($filesize>$maxfilesize) { $error_file .= "The submitted file was larger than a Megabyte.<br />"; $execute = "no"; } Quote Link to comment https://forums.phpfreaks.com/topic/54035-solved-file-upload-question-or-problem-rather/ Share on other sites More sharing options...
sebastiaandraaisma Posted June 2, 2007 Share Posted June 2, 2007 Maybe a stupid question but, do you get timed out maybe? My webhost has a timeout after 3 minutes I have to use the .htaccess to over rule this. Just a thought Kind regards, Sebas Quote Link to comment https://forums.phpfreaks.com/topic/54035-solved-file-upload-question-or-problem-rather/#findComment-267156 Share on other sites More sharing options...
Solarpitch Posted June 2, 2007 Author Share Posted June 2, 2007 Hey . . . that might actually be the problem now that I think of it! How do you implement the .htaccess to over rule it? Quote Link to comment https://forums.phpfreaks.com/topic/54035-solved-file-upload-question-or-problem-rather/#findComment-267160 Share on other sites More sharing options...
Solarpitch Posted June 2, 2007 Author Share Posted June 2, 2007 Actually . . probably not the problem. Starting to happen to files the size of 46kb! Quote Link to comment https://forums.phpfreaks.com/topic/54035-solved-file-upload-question-or-problem-rather/#findComment-267161 Share on other sites More sharing options...
Solarpitch Posted June 2, 2007 Author Share Posted June 2, 2007 Ok, just an update . . It doesnt seem to work with files more than 5kb but less is fine! Quote Link to comment https://forums.phpfreaks.com/topic/54035-solved-file-upload-question-or-problem-rather/#findComment-267169 Share on other sites More sharing options...
sebastiaandraaisma Posted June 2, 2007 Share Posted June 2, 2007 Wow 5000 bytes? Than I can no longer help you anymore. I'm only able to solve problems that I have experienced myself (I'm not an expert). Well just wait a little, there are so many people here on this forum that know so much more than me that I'm pretty sure you will get it to work! Kind regards, Sebas. Quote Link to comment https://forums.phpfreaks.com/topic/54035-solved-file-upload-question-or-problem-rather/#findComment-267181 Share on other sites More sharing options...
Solarpitch Posted June 2, 2007 Author Share Posted June 2, 2007 Thanks . .just as you posted that I figured it out. The problem was with the HTML <input type="hidden" name="MAX_FILE_SIZE" value="20000)"> should of been... <input type="hidden" name="MAX_FILE_SIZE" value="1048576)"> It was causing a conflict! Thanks anyway! Quote Link to comment https://forums.phpfreaks.com/topic/54035-solved-file-upload-question-or-problem-rather/#findComment-267183 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.