Jump to content

Strange behaviour regarding upload [small code]


play_

Recommended Posts

Here's the code:

 

<form action="#" method="post" enctype="multipart/form-data">
<input type="file" name="upfile" />
<input type="submit" name="submit" />
</form>


<?php

if(isset($_POST['submit'])) {
echo "<pre>";
print_r($_FILES);
echo "</pre>";
}
?>

 

PHP.INI has upload size limit of 2M.

Ok, If i upload small files, like images, texts, etc. it works. as expected.

 

Now i upload an image of ~3M.

Array
(
    [upfile] => Array
        (
            [name] => untitled.bmp
            [type] => 
            [tmp_name] => 
            [error] => 1
            [size] => 0
        )

)

 

gave me an error of 1, which according to the manual, "Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini."

Ok. that works as expected.

 

then i go on and try uploading a video file. tried ones of 20M and over.

Nothing happens. No errors. Array doesn't print out. Just blank.

Any thoughts?

 

 

I believe apache has a upload limit also, not much you can do here unless you develop a system to stream a file off the hard drive to your server and php lacks that support. 

 

Good test is use javascript and verify a valid extension on it, helps a bit

I am using javascript thus far.

 

But what if the user turns javascript off?

 

I am using this: http://www.fyneworks.com/jquery/multiple-file-upload/

 

So, on the server side, i  also  validate each file, with a for loop. But if one file is too big, the entire $_FILES array shows up as blank. Not just the really big file array (ie $_FILES['bigfile']). So i can't even report an error back saying "file $_FILES['upload']['movie.avi'] is too big to be uploaded'.

A non-existent $_FILES array means you have exceed the post_max_size setting.

 

 

Not technically as it could be you uploaded 0 files, the array always populates I believe if multi type post is sent.  But you can simply add to your error checking if(empty($_FILES['File'.$n])  die

PFMaBiSmAd:

Not true. Upload limit is 2M. i uploaded a 3.5mb file and it worked.

 

cooldude:

Not technically as it could be you uploaded 0 files, the array always populates I believe if multi type post is sent.  But you can simply add to your error checking if(empty($_FILES['File'.$n])  die

 

That was what caused me to post here. The problem with that, is that i need to count() the $_FILE array to be able to go through the arrays inside. and it won't let me do that if one file is too big, because $_FILE will be empty.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.