File Upload Size Validation

心已入冬 提交于 2019-12-04 09:49:08

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

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.

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

This method work fine for all cases of errors when upload file , even if filesize is greater than MAX_FILE_SIZE, upload_max_filesize or post_max_size (from php.ini)

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!