Check file upload size

Validations are a big problem, since if I check in php, it has all the functions, etc. I need to make her work. But she first uploads the file to a temporary location, and then checks that sucks. If someone uploads a file at 100mb, he should wait a while to not get any errors, but only some internal php hang, hanging page.

One way: JS

//file is id of input file
alert(document.getElementById('file').files[0].fileSize);

This works in firefox, safari, chrome, I think too. NOT: In opera, of course, IE, but IE can take care of the size of the ActiveX file, but Opera I'm still stuck. So beautifully unfit, anyway, to get around him?

Secondly: I was thinking if I could give a custom php alert or something by setting the maximum size in php.ini or something like that that could easily solve the problem. What I'm looking for.

OTHER UPDATE:

I tricked myself with rapidshare to understand what was happening, I realized that even they use javascript file size check: P Now it works fine with firefox, and others, as I said, even IE, because it has ActiveX rollback method, but Opera is the victim: P They cannot come up with a fantasy JavaScript error in this case. But they have a rollback, the server-side check takes a few seconds, is not smooth, but it finally shows a small error.

So you just need to find out that the part on the server side is not loading now, and in my opinion there is only one way to do this:

  • php max , script, , POST - . // . , :) , , , - php server .

. .:)

+5
3

, flash + javascript (MooTools) . , , Github . .. . , PHP , .

Fancyupload

  • .
  • ,
  • , Flash9 + ( > 95% ),

jQuery, , MooTools:

Uploadify

+1

, PHP, Javascript Apache.

Javascript , .

PHP .

Apache , , , ( ) .

0

.

$_SERVER['CONTENT_LENGTH'] . , .

if(isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH']>2097152)
$error = 'Upload FAILED, file is too large !';

This method works great for all cases of errors when downloading a file, even if the file size is larger MAX_FILE_SIZE, upload_max_filesizeor post_max_size(from php.ini)

Additional features you can try http://valums.com/ajax-upload/

0
source

All Articles