BuildMyWeb Posted November 14, 2012 Share Posted November 14, 2012 (edited) im using the following in a local php.ini file settings; max_execution_time = 900 ; Maximum execution time of each script, in seconds session.gc_maxlifetime = 900 max_input_time = 900 ; Maximum amount of time each script may spend parsing request data memory_limit = 150M ; Maximum amount of memory a script may consume (16MB) post_max_size = 150M upload_max_filesize = 150M ; Maximum allowed size for uploaded files. i have a file of 121MB that will not upload. am i missing something in the php.ini? is there more i can be doing? the following i copied out of my phpinfo.php file to verify settings: max_execution_time 900 900 session.gc_maxlifetime 900 900 max_input_time 900 900 post_max_size 150M 150M upload_max_filesize 150M 150M memory_limit 150M 150M Edited November 14, 2012 by BuildMyWeb Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/ Share on other sites More sharing options...
requinix Posted November 14, 2012 Share Posted November 14, 2012 What is the error code from the upload? It's in $_FILES["whatever"]["error"]. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392413 Share on other sites More sharing options...
BuildMyWeb Posted November 15, 2012 Author Share Posted November 15, 2012 sorry i took this long to reply. cant get an error. this is what imm troubleshooting with and the response is without a value; "error: " if( $_FILES['upload']['error'] > 0 ) { $error_msg = $_FILES['upload']['error']; echo"error: " . $error_msg; switch( $_FILES['upload']['error'] ) { case 0: echo"0"; break; case 1: echo"1"; break; case 2: echo"2"; break; case 3: echo"3"; break; case 4: echo"4"; break; case 5: echo"5"; break; case 6: echo"6"; break; case 7: echo"7"; break; default: echo"not sure"; break; } } Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392759 Share on other sites More sharing options...
Christian F. Posted November 15, 2012 Share Posted November 15, 2012 (edited) Run a var_dump () on the $_FILES array, should give you (and us) more to work with. Also, please post your actual form here, if you still can't figure it out after doing the above. Edited November 15, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392762 Share on other sites More sharing options...
BuildMyWeb Posted November 15, 2012 Author Share Posted November 15, 2012 got nothin: array(0) { } Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392776 Share on other sites More sharing options...
Christian F. Posted November 15, 2012 Share Posted November 15, 2012 Well.. There's your problem. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392784 Share on other sites More sharing options...
requinix Posted November 16, 2012 Share Posted November 16, 2012 Did you remember to include the enctype on the form? Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392806 Share on other sites More sharing options...
BuildMyWeb Posted November 16, 2012 Author Share Posted November 16, 2012 (edited) yes, enctype is there. and many files have been uploaded successfully. its this one instance that im having trouble. its an .exe file that client wants to be uploaded (despite my advising against that extension) of 128MBs. its the largest to-date so i thought maybe file size was the issue. smaller .exe files successfully upload as well. so i dont know where to go from here. <form action='xxx.php' method='POST' enctype='multipart/form-data'> <div class='form_text'>Document:</div> <div class='form_input'><input type='file' name='upload' /></div> <div class='form_text'>File Name:</div> <div class='form_input'><input type='text' size='25' maxlength='25' name='file_name' /></div> <div style='height:40px;'></div> <div class='form_text'>Category:</div> <div class='form_input'><input type='text' size='25' maxlength='25' name='category' /></div> <div class='form_text'>Destination:</div> <div class='form_input'><input type='radio' name='dest' value='priv' checked='checked'>Private<input type='radio' name='dest' value='pub'>Public</div> <div style='height:40px;'></div> <div class='submit_button'><input type='submit' value='Upload'/></div> </form> Edited November 16, 2012 by BuildMyWeb Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392823 Share on other sites More sharing options...
AyKay47 Posted November 16, 2012 Share Posted November 16, 2012 double check that the directives are being set correctly by running phpinfo() Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392832 Share on other sites More sharing options...
BuildMyWeb Posted November 16, 2012 Author Share Posted November 16, 2012 double check that the directives are being set correctly by running phpinfo() thanks aykay. but i dont know what you mean by this Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392839 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2012 Share Posted November 16, 2012 double check that the directives are being set correctly by running phpinfo() That's exactly what the OP did in the very first post. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392840 Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2012 Share Posted November 16, 2012 An empty $_FILES array is generally a symptom of exceeding the max_post_size setting. What does echoing $_SERVER['CONTENT_LENGTH'], on the line right before your if( $_FILES['upload']['error'] > 0 ) statement, show? Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392844 Share on other sites More sharing options...
AyKay47 Posted November 16, 2012 Share Posted November 16, 2012 That's exactly what the OP did in the very first post. Really? because I'm seeing output from a local php.ini file which I am not convinced is even in the right place to affect the script. OP, place phpinfo in your script and post the output for the directives post_max_size and upload_max_filesize Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392898 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2012 Share Posted November 16, 2012 Then you must not have even read the post. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392947 Share on other sites More sharing options...
BuildMyWeb Posted November 16, 2012 Author Share Posted November 16, 2012 @ PFMaBiSmAd content length = 127620926 Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392970 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2012 Share Posted November 16, 2012 Have you ever been able to upload anything with this script, or is it just this one file that's failing? You should probably post the rest of the code; there's something odd about all this. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392975 Share on other sites More sharing options...
BuildMyWeb Posted November 16, 2012 Author Share Posted November 16, 2012 yes pikachu. i noted that a little earlier in the thread; yes, enctype is there. and many files have been uploaded successfully. its this one instance that im having trouble. its an .exe file that client wants to be uploaded (despite my advising against that extension) of 128MBs. its the largest to-date so i thought maybe file size was the issue. smaller .exe files successfully upload as well. so i dont know where to go from here. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392978 Share on other sites More sharing options...
BuildMyWeb Posted November 16, 2012 Author Share Posted November 16, 2012 (edited) i have the form posted higher in the thread. here is the handler: <?php // START FUNCTIONS function clean_string( $string ) { $string = trim( $string ); $string = htmlentities( $string ); $string = strip_tags( $string ); return $string; } // END FUNCTIONS $file_name = clean_string( $_POST['file_name'] ); $category = clean_string( $_POST['category'] ); $dest_page = clean_string( $_POST['dest'] ); // priv or pub $rootDir = '/home/xxx/xxx/' . $dest_page . '/'; //echo"content length = " . $_SERVER['CONTENT_LENGTH']; // if there is an error with file upload if( $_FILES['upload']['error'] > 0 ) { switch( $_FILES['upload']['error'] ) { case 1: echo"upload_max_filesize exceeded"; break; case 2: echo"max_file_size exceeded"; break; case 3: echo"File only partially uploaded"; break; case 4: echo"No File uploaded"; break; case 6: echo"No temp directory specified"; break; case 7: echo"Cannot write to disk"; break; default:echo"File Upload problem: unspecified"; break; } } // get the values of the $_FILES array //var_dump( $_FILES ); $name_raw = $_FILES['upload']['name']; $file_ext = substr( strrchr($name_raw, '.') ,1 ); $array_safe_ext = array("txt","csv","htm","html","xml","css","doc","xls","rtf","ppt","pdf","swf","flv","avi","wmv","mov","jpg","jpeg","gif","png","bmp","zip","rar","exe","log","bat"); $num = count( $array_safe_ext ); $counter = 0; foreach( $array_safe_ext as $safe_ext ) { // add one for each $array_safe_ext that doesnt match the $file_ext if( $file_ext != $safe_ext ) $counter++; } // if $file_ext does not match any values in $array_safe_ext, its an unsafe extenstion if( $num == $counter ) { echo"<div style='margin:200px 30px;'>That file type is not allowed. Please <a href='mailto:james@buildmyweb.org?subject=Sentry Uploads'>contact</a> the site administrator and <a href='../tech_links.php'>try again</a>.</div>"; exit(); } else { if( is_uploaded_file($_FILES['upload']['tmp_name']) ) { if( !empty($file_name) ) $destinationURL = $file_name . ' - ' . $name_raw; else $destinationURL = $name_raw; if( empty($category) ) $category = "Common"; else if( file_exists($rootDir . $category) ) echo"Adding to $category directory..."; else mkdir( '../uploads/' . $dest_page . '/' . $category ); $destination = $rootDir . $category . '/' . $destinationURL; if( move_uploaded_file($_FILES['upload']['tmp_name'], $destination) ) { echo" <div style='margin:200px 30px;'> <p>Thank you. Your file was uploaded.</p> <p>Please <a href='../tech_links.php'>continue</a>.</p> </div> "; } else echo"<div style='margin:200px 30px;'>There was a problem moving your file. Please <a href='../tech_links.php'>try again</a>.</div>"; } // close if( is_uploaded_file($_FILES['upload']['tmp_name']) ) else { echo"You do not have permission to access that file."; } } // Close else ?> Edited November 16, 2012 by BuildMyWeb Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392980 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2012 Share Posted November 16, 2012 OK, so that's the actual code for the form. How about posting the code that processes the form? Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392981 Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2012 Share Posted November 16, 2012 I'm going to guess your web host has imposed a maximum post size limit on the sever that is independent of php's settings. Have you checked the web host's FAQ section or asked the web host? Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392984 Share on other sites More sharing options...
BuildMyWeb Posted November 16, 2012 Author Share Posted November 16, 2012 I'm going to guess your web host has imposed a maximum post size limit on the sever that is independent of php's settings. Have you checked the web host's FAQ section or asked the web host? ill try this. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392985 Share on other sites More sharing options...
AyKay47 Posted November 16, 2012 Share Posted November 16, 2012 Talk about not reading the post... Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392988 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2012 Share Posted November 16, 2012 sorry i took this long to reply. cant get an error. this is what imm troubleshooting with and the response is without a value; "error: " if( $_FILES['upload']['error'] > 0 ) { $error_msg = $_FILES['upload']['error']; echo"error: " . $error_msg; switch( $_FILES['upload']['error'] ) { case 0: echo"0"; break; case 1: echo"1"; break; case 2: echo"2"; break; case 3: echo"3"; break; case 4: echo"4"; break; case 5: echo"5"; break; case 6: echo"6"; break; case 7: echo"7"; break; default: echo"not sure"; break; } } You say this code is outputting "error: ". AFAICT, it shouldn't output anything at all if the ['error'] index doesn't exist, except for maybe a undefined index notice. That's why I was saying something seems odd to me. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392991 Share on other sites More sharing options...
AyKay47 Posted November 16, 2012 Share Posted November 16, 2012 (edited) The only thing I can think of for the code Pikachu posted is that there are 8 possible values for $_FILES[]['error'] and the OP has 7 in the switch. But even so, $error_msg should output the error value, the default switch value should output as well, something. That's what initially jumped out at me as well when reading the code. Edited November 16, 2012 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1392995 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2012 Share Posted November 16, 2012 The only thing I can think of for the code Pikachu posted is that there are 8 possible values for $_FILES[]['error'] and the OP has 7 in the switch. But even so, $error_msg should output the error value as well as the default switch value. That's what initially jumped out at me as well when reading the code. The echo is conditional upon the existence of $_FILES['[upload']['error']. The subsequent var_dump() shows an empty array. The conditional should return FALSE, and there should be no output at all. Quote Link to comment https://forums.phpfreaks.com/topic/270687-problems-uploading-files-via-php/#findComment-1393001 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.