Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File Upload Size Validation

Validations are a big problem, as if i validate in php it has all the functions etc i need to make it work.. But it uploads the file first on a temporary location and then checks, which sucks. If someone uploads a file of 100mb he has to wait for the time just to get no error, but just some internal php screw up hanging the page.

One Way: JS

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

This works in firefox, safari, chrome i guess too, NOT: In opera, quite sure IE too but IE can be taken care of by ActiveX file size but Opera i am still stuck. So pretty unusable, anyways to get around it?

Second: I was thinking, can i give a php custom alert or something by setting max size in php.ini or something like that, that could easily solve the problem. Thats what i am looking for.

ANOTHER UPDATE:

I have been fooling around with rapidshare to understand whats going on, i realized even they use javascript file size checking :P Now that works great with firefox, and the others like i said, even IE as it has a fall back ActiveX method but Opera is the victim :P They cant give a fancy javascript error in that case. But they do have a fall back server side validation takes a few seconds more, is not smooth but it does show a small error finally.

So just need to find out that server side part now without uploading, and in my mind only one way to do it:

  1. Some Internal php max size increased error which i can customize or run some script to find out whether max size has been reached or find POST exceeded or anything like that. // NO IDEA ABOUT THIS. Hopefully some server guy can help :) I think this is what will solve it if anyone a php server guru here.

Thanks AND Regards. Please help. :)

like image 964
Aakash Thakkar Avatar asked Nov 14 '22 03:11

Aakash Thakkar


1 Answers

Here is a plugin that uses flash + javascript (MooTools) to do file upload. The upside to this plugin is that it's supported and you can Github it. It can limit max size, etc, and verify file information before upload. Also, has example for backend using PHP on how files are handled after it is uploaded.

Fancyupload

Features

  • Select and upload multiple files
  • Filter files by type in the select
  • dialog A lot of possible Events to add your own behaviour
  • Show and filter useful file information before the upload starts
  • Limit uploads by file count, type or size
  • Platform and server independent, just needs Flash9+ (> 95% penetration) which works on all browsers with it installed

Here is the jQuery plugin that does the same as the MooTools one:

Uploadify

like image 59
KJYe.Name Avatar answered Dec 17 '22 16:12

KJYe.Name