如何使用$ _FILES [“file”] [“size”]?

时间:2021-10-22 23:15:07

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

谢谢

2 个解决方案

#1


41  

Arithmetic 101: 5MB -> 5 * 1024 * 1024 bytes

算术101:5MB - > 5 * 1024 * 1024字节

or... if you're a storage vendor, then it's actually 5 * 1000 * 1000.

或者...如果您是存储供应商,那么它实际上是5 * 1000 * 1000。

#2


99  

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)

#1


41  

Arithmetic 101: 5MB -> 5 * 1024 * 1024 bytes

算术101:5MB - > 5 * 1024 * 1024字节

or... if you're a storage vendor, then it's actually 5 * 1000 * 1000.

或者...如果您是存储供应商,那么它实际上是5 * 1000 * 1000。

#2


99  

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)