$_FILES['size'] File is too large...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

$_FILES['size'] File is too large...

Post by hawleyjr »

I'm creating a file upload page. My server has a restriction of 2MB per file. This is fine, however, I want to inform the user that the reason the file didn't upload was because it is too large. I attempted to solve this by using the following code:

Code: Select all

<?php
	foreach($_FILES as $a_file){	
		//CALCULATE TOTAL FILE SIZES
		$total_file_size += $a_file['size'];
	}
if($total_file_size>BYTES_IN_ON_MEG*2){
//INFORM USER
}
?>
This is what the $_FILES looks like:

Code: Select all

<?php
Array
(
    [new_file_0] => Array
        (
            [name] => dream car.mpeg
            [type] => 
            [tmp_name] => 
            [error] => 1
            [size] => 0
        )

    [new_file_1] => Array
        (
            [name] => IMG_0704.jpg
            [type] => image/pjpeg
            [tmp_name] => /tmp/php0xtsin
            [error] => 0
            [size] => 883720
        )

)
?>
Is there a way for me to determine the file size before the server throws the error?

Also, how can I change the 2 MB limit?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]ini_set[/php_man]() upload_max_filesize and post_max_size
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Thanks again Feyd...

Now check this out. It uploaded the file but look at the file size:

Code: Select all

<?php
Array
(
    [new_file_0] => Array
        (
            [name] => dream car.mpeg
            [type] => video/mpeg
            [tmp_name] => /tmp/phpFFlTgN
            [error] => 0
            [size] => 0
        )

    [new_file_1] => Array
        (
            [name] => IMG_0704.jpg
            [type] => image/pjpeg
            [tmp_name] => /tmp/phpr5GZqR
            [error] => 0
            [size] => 883720
        )

)
?>
I looked on the server. same thing it had a file size of 0?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

I just tried it with a different file...

Didn't work...?

Code: Select all

<?php
Array
(
    [new_file_0] => Array
        (
            [name] => Eraser56Setup.zip
            [type] => 
            [tmp_name] => 
            [error] => 1
            [size] => 0
        )

    [new_file_1] => Array
        (
            [name] => Untitled-1.gif
            [type] => image/gif
            [tmp_name] => /tmp/phpyV9l4m
            [error] => 0
            [size] => 939
        )

)
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

looks like it didn't accept the zip file, as for the mpeg, not sure..
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

No, it's actually not working at all. The my first "It worked" wasn't true. I just refreshed the page and there it was. however, when i went back and tried it again I got the error.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hmm.. what's your submitting form look like? Also, what's your new settings for upload_max and post_max?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

PHPINFO():

Code: Select all

post_max_size 55M 55M 
upload_max_filesize 2M 2M
There really isn't anything special with my form, is it just possible that ini_set() didn't work?

Code: Select all

<form action="newreq_process.php" method="post" enctype="multipart/form-data" name="form1">
  <table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr> 
      <td width="100%">&nbsp;</td>
    </tr>
    <tr> 
      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr valign="top"> 
            <td nowrap> <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr> 
                  <td>&nbsp;</td>
                </tr>
                <tr> 
                  <td valign="top"><input type="file" name="new_file_0" size=30></td>
                </tr>
                <tr> 
                  <td valign="top"><input type="file" name="new_file_1" size=30></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
    </tr>
    <tr> 
      <td><input type="submit" name="Submit" value="Submit Request"></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
Post Reply