showing error on uploading a big file using php

Posted by user1489969 on Stack Overflow See other posts from Stack Overflow or by user1489969
Published on 2012-11-01T05:55:10Z Indexed on 2012/11/01 11:01 UTC
Read the original article Hit count: 175

Filed under:
|
|

I have created a php code to display the upload option to upload multiple files as below:

 <?php
   $f_id= $_GET["id"];
  ?>

 <title>Upload File</title>
 <form enctype="multipart/form-data" method="post" action="upload_hal_mult.php?id=<?php echo $f_id;?>" > 
 <input type="hidden" name="MAX_FILE_SIZE" value="10000000"> 
 <input id="infile" type="file" name="infile[]" multiple="true" />
 <input type="submit" value="upload" name="file_uploaded"  / >  
 <br>
 <br>
 </form>

So this will call "upload_hal_mult.php" when "upload" button is clicked. And the code for that is as follows:

 <title>Upload Results</title>
 <?php
   define("MAX_SIZE",10000000); 
   $f_id= $_GET["id"];
   $dir_name="dir_hal_".$f_id;
   $u=0;
   if (!is_dir($dir_name))
   mkdir($dir_name);
   $dir=$dir_name."/";
   $file_realname = $_FILES['infile']['name'];
   for ($i = 0; $i < count($_FILES['infile']['name']); $i++) 
   {
     $ext = substr(strrchr($_FILES['infile']['name'][$i], "."), 1); 
     $fname = substr($_FILES['infile']['name'][$i],0,strpos($_FILES['infile']['name'][$i], ".")); 
     $fPath = $fname."_(".substr(md5(rand() * time()),0,4).")".".$ext";
     echo "files size=".$_FILES["infile"]["size"][$i]."\n";
     if($_FILES["infile"]["size"][$i]>MAX_SIZE)
       echo('File uploaded exceeds maximum upload size.');
     if(($_FILES['infile']['error'][i]==0) && move_uploaded_file($_FILES['infile']['tmp_name'][$i], $dir . $fPath))
     {
       $u=$u+1;
     ?>
     <!--<script type="text/javascript">setTimeout("window.close();", 1300);</script>-->
     <?php
      echo "Upload is successful\n";
      }
      else
       echo "if stmt failed so error \n";
     }   

     if($u!=count($_FILES['infile']['name']))
       echo "Error";
     else
       echo "count is correct";
   ?>

This upload works correctly for files of size<10MB. But for files of size>10MB, it's not echoing 'File uploaded exceeds maximum upload size.' as expected. Its also not uploading the file of size>10MB. But the $u gets incremented. But none of the statements like "Upload is successful" or "if stmt failed so error" are being echoed as well.

However the statement "count is correct" is being displayed, and this shows the $u got incremented somehow even though the echo statements didnt work! Can someone please point out the error I am doing here? I thought its simply a matter of 'if/else' statements but it seems more than that to me. Please help me out if you have any clue. Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about html