php 如何使用 $_FILES["file"]["size"]?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14758191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use $_FILES["file"]["size"]?
提问by John Titer
how can I see if the file loaded weighs less than 5MB? I am using
如何查看加载的文件是否小于 5MB?我在用
$ _FILES ["file"] ["size"]
but I do not know how to set 5mb, because the value must be expressed in bytes, from what I understand. So how to do
但我不知道如何设置 5mb,因为根据我的理解,该值必须以字节表示。那怎么办
$ _FILES ["file"] ["size"] <(5mb)
thanks
谢谢
回答by Martin
To keep code clear, I often define units as constants:
为了保持代码清晰,我经常将单位定义为常量:
define('KB', 1024);
define('MB', 1048576);
define('GB', 1073741824);
define('TB', 1099511627776);
Then you can simply do your condition like
然后你可以简单地做你的条件
if ($_FILES['file']['size'] < 5*MB)
回答by Marc B
5MB -> 5 * 1024 * 1024 bytes
5MB -> 5 * 1024 * 1024 字节
or... if you're a storage vendor, then it's actually 5 * 1000 * 1000.
或者...如果您是存储供应商,那么它实际上是 5 * 1000 * 1000。

