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:
- 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. :)
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
Here is the jQuery plugin that does the same as the MooTools one:
Uploadify
You can set the max size allowed in PHP, Javascript & Apache.
Use Javascript for the most user friendly, since it alerts the user immediately.
Use PHP next to have an simple way to check after upload.
Use Apache last since it's pretty low level and I believe checking for too large of a file (to give a nice alert to the user) is more difficult this way.
You can use a server-side solution.
Use
$_SERVER['CONTENT_LENGTH']
after trying to upload file. This variable returns size of uploaded file, even if upload failed.This method work fine for all cases of errors when upload file , even if filesize is greater than
MAX_FILE_SIZE
,upload_max_filesize
orpost_max_size
(from php.ini)For more features you can try http://valums.com/ajax-upload/