即使不应该下载该文件,是否也会将其下载到站点?

发布于 2024-09-07 14:09:39 字数 294 浏览 5 评论 0原文

我确信这是有史以来最史诗般的游戏之一。所以,我有像这里这样的上传表单。我规定人们只能上传最多 1 MB 的文件。但是,如果我尝试上传 1 GB 的文件,则需要很长时间才会出现错误。那么,这就来了一个问题。在检查文件大小之前,该文件是否正在我的主机中下载,或者是否从我的主机中占用资源?尽管如果我尝试上传 2 MB 文件,但在 1 秒内就会出现错误,为什么要花很长时间才会出现错误? 谢谢您的解释。

I am sure this is the one of the most epic titles ever. So, I have upload form like here. I made that people could upload their files only up to 1 MB. But, if I try to upload for example 1 GB file, it takes ages before it gives me an error. So, here comes a question. Before checking file's size, does that file is being downloaded in my hosting or does it takes resources from my hosting? Why it takes ages and ages before it gives me an error although if I try to upload 2 MB file it gives me an error in 1 second?
Thank you for your explanations.

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

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

发布评论

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

评论(3

2024-09-14 14:09:39

如果您要检查服务器上的文件大小,那么,是的,它必须上传到服务器才能运行检查大小的 if 语句。

当然,您在客户端所做的任何检查都将受到客户端的支配。所以没有100%可靠的方法来做到这一点。 Artefacto 指出了一种吸引大多数用户的好方法。还有一个 JavaScript ActiveX 对象可能会有所帮助(http://www.kavoir.com/2009/01/check-for-file-size-with-javascript-before-uploading.html)但是,用户可以轻松禁用它(甚至是无意的)或者浏览器根本不支持它。

If you're checking the file size on the server then, yes, it will have to upload to the server in order to just run the if statement that checks the size.

Anything you do on the client side to check will, of course, be at the mercy of the client. So there is no 100% reliable way to do it. Artefacto pointed out one good way to catch most users. There's also a JavaScript ActiveX object that might help (http://www.kavoir.com/2009/01/check-for-file-size-with-javascript-before-uploading.html) but, again, users can easily disable it (even quite unintentionally) or have browsers that don't support it at all.

谎言月老 2024-09-14 14:09:39

您应该包含如下输入:

 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />

提示浏览器可以上传的最大文件大小。如果文件太错误,大多数浏览器都会警告用户。

如果用户提交一个文件,我认为 PHP 不会存储超过 php.ini 允许的最大帖子大小的文件(服务器不会有 1GB 的文件不必要地占用空间);然而,用户必须在服务器收到错误响应之前发送所有数据,因为 HTTP 协议没有提供中断客户端请求并过早发送响应的规定。

请注意,如果允许巨大的 POST 数据并将文件大小检查推迟到 PHP 脚本,则会使用更多磁盘空间。

You should include an input like:

 <input type="hidden" name="MAX_FILE_SIZE" value="30000" />

that hints the browser in respect to the maximum file size that can be uploaded. Most browsers will then warn the user if the file is too bug.

I don't think PHP will store files past the maximum post size allowed in php.ini if the user submits one (the server will not have a 1GB file occupying space unnecessarily); however, the user must send all the data before it gets the error response for the server because the HTTP protocol has no provision for interrupting the client's request and send a response prematurely.

Beware that if allow huge POST data and defer the file size check to your PHP script, more disk space will be used.

故事未完 2024-09-14 14:09:39

只是快速谷歌一下你的问题,我发现了这个旧的 stackoverflow 主题, 使用 jQuery,上传前限制文件大小 看来实际上可以阻止人们上传文件到大客户端,但只能使用flash/Java,也许这个软件会有所帮助http://www.swfupload.org/。描述中的第 9 个要点:在上传开始之前控制文件大小。

问候

卢克

Just having a quick google for your issue I found this old stackoverflow topic, Using jQuery, Restricting File Size Before Uploading It seems that it is infact possible to stop people uploading files to big client side but only using flash/Java, maybe this software will help http://www.swfupload.org/. 9th bullet point down on description: Control filesize before upload starts.

Regards

Luke

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