Connecting Tech Pros Worldwide Help | Site Map

uploading file with large size

xxoulmate's Avatar
Member
 
Join Date: May 2007
Posts: 61
#1: 3 Weeks Ago
i have uploading script.
limit in 2 mb
in php.ini 2mb also

when the size of file be upload is greater than 2 or less than 5 mb of course there's an error message return

but when the size of file to be upload is greater than let say 5 mb no error occurs it just refresh the page., when i try to simulate and look if submit is set, submit of form not detected too.
how can i trap that error
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,094
#2: 3 Weeks Ago

re: uploading file with large size


simplify your program to just the form and the validation check. Try again, if it happens again post the code.

I'm talking about a 10 line code, eliminate everything unnecessary and not related to the error.



Dan
xxoulmate's Avatar
Member
 
Join Date: May 2007
Posts: 61
#3: 3 Weeks Ago

re: uploading file with large size


here is my code:
php.ini config: maxfilesize = 2m

i set form MAX_FILE_SIZE to 2mb
when i upload a file below 5 mb., error occurs.
when i upload a file more than 5 mb no error occurs.,
when i check if form submitted success fully no "got here" message on my screen.


Expand|Select|Wrap|Line Numbers
  1.  if (isset($_REQUEST['btnattach'])) {
  2.    echo "got here";
  3.    if ($_FILES["file1"]["error"] > 0) { 
  4.     if ($_FILES["file1"]["error"] == 4) {
  5.      $errMsg = "Please specify a file to upload.";
  6.      }
  7.     else if ($_FILES["file1"]["error"] == 2) {
  8.      $errMsg = "Uploading failed, file size exceeds " . $fileSizeMb . "mb.";
  9.      }
  10.     else {
  11.      $errMsg =  "Attachment failed, Return Code: " . $_FILES["file1"]["error"] . "<br />"; }
  12.     }
  13.    else
  14.     {
  15.     $attachname = str_replace(" ","_",$_FILES["file1"]["name"]);
  16.  
  17.     if (file_exists("upload/" . $attachname)){
  18.      $errMsg =  "File already exist. ";}
  19.     else
  20.      {
  21.      if (move_uploaded_file($_FILES["file1"]["tmp_name"],"upload/" . $attachname)==false) {
  22.       $errMsg =  "Uploading failed. ";}
  23.      }
  24.     } 
  25.   }  
  26.  
  27. <form name="frm" id="frm" method="post" enctype="multipart/form-data" >
  28.    Filename: <?php echo "(max. " . str_replace("M"," mb",ini_get("upload_max_filesize")) . ")";?>
  29.     <input type="hidden" name="MAX_FILE_SIZE" value="2097152"> 
  30.     <input type="file" name="file1" id="file1" value="" />
  31.     <input type="submit" name="btnattach" id="btnattach" value="Attach Files" />
  32.   </form>
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#4: 3 Weeks Ago

re: uploading file with large size


Quote:

Originally Posted by xxoulmate View Post

here is my code:
php.ini config: maxfilesize = 2m

i set form MAX_FILE_SIZE to 2mb
when i upload a file below 5 mb., error occurs.
when i upload a file more than 5 mb no error occurs.,
when i check if form submitted success fully no "got here" message on my screen.

When you say, "error occurs", which error is it? Is it one of your errors or a PHP error? If it's a PHP error, please let us know exactly what it says.

Does "got here" get displayed ever?

I think that it's simply timing out. Have you increased your max execution time in your php.ini? What I think is happening is: When someone uploads something <5MB, the form is submitted with that file and then the file is analysed and rejected for being too big. When it is >5MB the form is not submitted because PHP times out before it can upload the whole file and send the form.

With PHP timeout, if a script is taking longer than x seconds, it will can it, and this is a security thing, so it's not good to set it too high or remove it incase someone who wanted to do you harm (or were just ignorant), blocks up your server with ridiculous requests which take forever to process.
didoamylee's Avatar
Newbie
 
Join Date: Nov 2008
Location: Köln , Deutschland
Posts: 15
#5: 3 Weeks Ago

re: uploading file with large size


Possible solutions...depends on the settings of the server.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. ini_set('upload_max_filesize','128M');
  3. ini_set('post_max_size','128M');
  4. ?>
  5.  
and something that actually worked when upload_max_filesize failed was to put the following line in my .htaccess file:
Expand|Select|Wrap|Line Numbers
  1. php_value memory_limit "128M"
xxoulmate's Avatar
Member
 
Join Date: May 2007
Posts: 61
#6: 3 Weeks Ago

re: uploading file with large size


no i dont need to enlarge the max size for upload
it's just no error occurs when uploading a file with size more than the max size
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#7: 3 Weeks Ago

re: uploading file with large size


Quote:

Originally Posted by xxoulmate View Post

no i dont need to enlarge the max size for upload
it's just no error occurs when uploading a file with size more than the max size

Did you read my response?
Reply