364,111 Members | 2127 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

uploading file with large size

xxoulmate
P: 73
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
Oct 26 '09 #1

✓ answered by didoamylee

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"
Share this Question
Share on Google+
6 Replies


dlite922
Expert 100+
P: 1,393
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
Oct 26 '09 #2

xxoulmate
P: 73
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>
Oct 27 '09 #3

TheServant
Expert 100+
P: 1,106
@xxoulmate
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.
Oct 28 '09 #4

didoamylee
P: 16
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"
Oct 29 '09 #5

xxoulmate
P: 73
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
Oct 30 '09 #6

TheServant
Expert 100+
P: 1,106
@xxoulmate
Did you read my response?
Oct 30 '09 #7

Post your reply

Help answer this question



Didn't find the answer to your PHP question?

You can also browse similar questions: PHP