目前,如果文件大小小于 1MB,我正在使用以下代码进行锻炼,但是因为以下代码来自 9lession 示例站点,它说要检查 1mb 的大小,但是如果我乘以 1024*2,它们就是在这里做的不是1mb而是2048kb
curretly I am using the following to workout if the file size is less than 1MB however as the following code was from 9lession example site it said to check the size for 1mb, but if I times 1024*2 which is what they are doing here it equals not 1mb but 2048kb
说它上传的大小不是kb,而是我理解的比特
saying that the size that it uploads is not in kb instead it from my understanding is bits
如果您感到困惑,我也是.我需要一种简单的方法来判断图像是否为 1mb 大小
if you're confused so am I. I need a simple way to tell if an image is 1mb size
if($size<(1024*1024))
我上传的图片及其大小:
image that i uploaded and its size:
**尺寸:**10514
**Size:**10514
也是我不想在服务器级别设置它的原因,因为我们也想做视频.我们仍在努力达到我们接受的视频最大尺寸限制.
Also the reason I don't want to set it on a server level because we also want to do videos. We are still working our the max-size limit we will accept for videos.
1MB
== 1048576
bytes1MB
== 1024
千字节你的问题不清楚,但无论如何我都会即兴发挥.
1MB
== 1048576
bytes1MB
== 1024
KbytesYou question is not clear, but I will just improvise anyhow.
如果你想限制文件上传到 <仅 1MB
!!然后,由于 $_FILES
数组将以字节为单位输出,您可以执行以下操作.
If you want to restrict file uploads to below < 1MB
only!! then, since the $_FILES
array, will output in bytes you can do the following.
if($_FILES['name']['size'] > 1048576){
//You can not upload this file
}
或者你想从浏览器级别限制它,你可以在你的表单中添加一个属性
Or you want want to restrict it from browser-level, you can add an attribute to your form as
form method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<input type="file" name="pictures" />
<input type="submit" value="upload" />
</form>
当然,任何人都可以轻松更改第二个选项,并且永远不要使用.
Offcourse, the second option can be changed by anyone easily, and should never be used.
这篇关于PHP 图像大小小于 1mb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!