Page 1 of 1

Max size query

Posted: Wed Feb 18, 2009 10:40 am
by Addos
Hi,
I’m trying to produce an error if a file size goes over 2MB using the following:

Code: Select all

if ($_FILES['fupload']['size'] > 25000) {
     $message_fileSize = '<b>SORRY! file size exceeds 2MB</b>';
echo $message_fileSize;
However this error is not being produced when a file goes over 2MB and just doesn’t upload either. I have run:

Code: Select all

print "error: ". $_FILES['fupload']['error'];
and this gives me 1 which suggests that the limit has been exceeded (when I deliberately upload 3MB file) in the .ini file which I have no access to so I’m wondering why I can’t show an error when I test the file being uploaded.

When I upload anything under 2MB the file uploads ok so my script is ok in that area.

Any thoughts?
Thanks

Re: Max size query

Posted: Wed Feb 18, 2009 10:51 am
by p3rk5
The default values in the .ini files only allow you to upload up to 2MB. You would have to change max_upload_size and max_post_size. Try this link: http://exaltations.net/weblogs/christef ... else_works

Re: Max size query

Posted: Wed Feb 18, 2009 11:02 am
by NOmeR1
What returns $_FILES['fupload']['size'] when size of file > 2 mb?

Re: Max size query

Posted: Wed Feb 18, 2009 11:26 am
by Addos
Thanks for the reply.
I understand that the ini file has a max of 2MB and that is ok but I just wanted to get this error to show if it's over 2MB.

The script I'm using is below:

Code: Select all

if ($_FILES['fupload']['type'] == "audio/mpeg") {
  // Test for file size
 if ($_FILES['fupload']['size'] > 25000) {
     $message_fileSize = '<b>SORRY! file size exceeds 2MB</b>';
 } else {
    $source = $_FILES['fupload']['tmp_name'];
    $target = "audio/mp3/" .$_FILES['fupload']['name'];
etc etc
And in the Form I have:

Code: Select all

 <?php  if (isset($message_fileSize) && !empty($message_fileSize)) {
          echo $message_fileSize ;  ?>  
But it seems to simply ignore this conditional statement.

$_FILES['fupload']['size'] when size of file > 2 mb? actually returns a 0 value.

Thanks

Re: Max size query

Posted: Wed Feb 18, 2009 2:50 pm
by pickle
Well, 25000 bytes = 25KB, not 2MB

When the user tries to upload the file, look in $_FILES['fupload']['error']. If that value is equal to UPLOAD_ERR_INI_SIZE, the problem was the file was too big. PHP does the size checking for you - no need to duplicate functionality.

I'd recommend taking a look at the PHP docs for handling HTTP file uploads