如何限制用户上传更多然后5MB到服务器? [英] How can I limit users from uploading more then 5MB to the server?

查看:130
本文介绍了如何限制用户上传更多然后5MB到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过PHP的地方进行检查,以确定该文件是很大的,问题是,用户必须首先将文件上传到服务器上,这样我才可以做检查。

I have a check in place via php to determine if the file is to big, the problem is, user has to upload the file to the server first, before i can make the check.

因此​​,如果有人要浪费我的带宽,一切又woudl所要做的是一个巨大的文件重命名为.jpg文件,例如并上传。并没有什么我能做的制止他们。

So if someone wanted to waste my bandwidth, all they woudl have to do is rename a huge file to .jpg for example and upload it. And there is nothing i can do to stop them

必须有某种方式来prevent这一点。某种有效的支票或jquery的什么的。

There must be some way to prevent this. Some kind of a valid check or jquery or something.

我需要一个解决方案,让我通知他试图上传的文件过大的用户。

I need a solution that would allow me to notify the user that the file he is trying to upload is too big.

感谢。

推荐答案

如果你担心浪费带宽,那么你必须在你的服务器堆栈更高层次处理这个问题。到时候PHP是处理为时已晚,上传已经发生文件和所消耗的带宽。

If you're concerned about wasting bandwidth, then you must handle this at a higher level in your server stack. By the time PHP is handling the file it's too late, the upload has already occurred and the bandwidth consumed.

阿帕奇有一些配置指令可能是有用的:

Apache has some configuration directives that may be useful:

http://httpd.apache.org/docs/current/ MOD / core.html#limitrequestbody

但我不知道,如果连实际上切断请求时身体超出了限制。如果没有,你就必须动起来另一个级别和TCP层处理它。

But I'm not sure if even that actually cuts off the request when the body exceeds the limit. If not, you'd have to move up yet another level and handle it at the TCP level.

如果你想往下走非PHP路线试图阻止大量上载,你应该问关于ServerFault,而不是计算器。

If you do want to go down a non-PHP route to try to block large uploads, you should ask on ServerFault instead of StackOverflow.

这篇关于如何限制用户上传更多然后5MB到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆