Jump to content

Strange behaviour regarding upload [small code]


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?

 

 

Perhaps it times out?  A timeout could occur either on the server or on your browser.  Or there could be underlying network instability that means that long-running transfers like that tend to be broken part-way through.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.