文件上传大小验证

发布于 2024-10-17 01:44:43 字数 907 浏览 2 评论 0原文

验证是一个大问题,就好像我在 php 中验证它具有我需要使其工作的所有功能等。但是它首先将文件上传到临时位置,然后进行检查,这很糟糕。如果有人上传了 100mb 的文件,他必须等待一段时间才不会出现错误,但只是一些内部 php 搞砸了页面。

一种方式:JS

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

这适用于 firefox、safari、chrome 我猜也适用,而不是:在 Opera 中,相当肯定 IE 也适用,但 IE 可以通过 ActiveX 文件大小来处理,但 Opera 我仍然卡住了。太不可用了,无论如何都要绕过它吗?

第二:我在想,我可以通过在 php.ini 中设置最大大小或类似的东西来提供 php 自定义警报或其他东西,这样可以轻松解决问题。这就是我正在寻找的。

另一个更新:

我一直在使用rapidshare来了解发生了什么,我意识到他们甚至使用javascript文件大小检查:P现在这与firefox以及其他像我说的,甚至IE一起工作得很好因为它有一个后备 ActiveX 方法,但 Opera 是受害者:P 在这种情况下他们不能给出一个奇特的 javascript 错误。但他们确实有一个后备服务器端验证需要多花几秒钟,并不顺利,但最终确实会显示一个小错误。

所以现在只需要找出服务器端部分而无需上传,在我看来只有一种方法可以做到这一点:

  1. 一些 内部 php 最大大小增加 我可以自定义或运行的错误 一些脚本来确定是否最大 大小已达到或找到POST 超过或类似的东西。 // 对此一无所知。希望有一些 服务器人员可以帮忙:)我认为这个 如果有人 php服务器专家在这里。

谢谢并问候。请帮忙。 :)

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. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦罢 2024-10-24 01:44:43

这是一个使用flash + javascript(MooTools)进行文件上传的插件。该插件的优点是它受支持,您可以 Github 它。它可以限制最大大小等,并在上传之前验证文件信息。另外,还有使用 PHP 的后端示例,说明文件上传后如何处理。

Fancyupload

功能

  • 选择并上传多个文件
  • 在选择对话框中按类型过滤文件
  • 许多可能的事件
    添加您自己的行为
  • 在之前显示和过滤有用的文件信息
    上传开始
  • 按文件数量、类型或大小限制
  • 上传 平台和服务器独立,只需要 Flash9+(> 95% 渗透率),可在安装了该插件的所有浏览器上运行

这是 jQuery 插件,其功能与 MooTools 插件相同:

< a href="http://www.uploadify.com/documentation/" rel="nofollow">Uploadify

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

凉城凉梦凉人心 2024-10-24 01:44:43

您可以设置 PHP、Javascript 和 PHP 中允许的最大大小。阿帕奇。

使用 Javascript 是最用户友好的,因为它会立即提醒用户。

接下来使用PHP有一个简单的方法来检查上传后。

最后使用 Apache,因为它的级别相当低,而且我相信通过这种方式检查文件是否太大(向用户发出良好的警报)会更加困难。

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.

梦巷 2024-10-24 01:44:43

您可以使用服务器端解决方案。

尝试上传文件后使用 $_SERVER['CONTENT_LENGTH']。即使上传失败,此变量也会返回上传文件的大小。

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

此方法适用于上传文件时出现的所有错误情况,即使文件大小大于 MAX_FILE_SIZEupload_max_filesizepost_max_size(来自 php.ini) )

有关更多功能,您可以尝试 http://valums.com/ajax-upload/

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文