Jump to content

Problems Uploading Files Via Php


BuildMyWeb

Recommended Posts

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 by BuildMyWeb
Link to comment
Share on other sites

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;
       }
   }

Link to comment
Share on other sites

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 by BuildMyWeb
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 by BuildMyWeb
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by AyKay47
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.