如何查看上传的图片大小是否大于2MB? [英] how to check uploaded image size is greater than 2MB in php?
本文介绍了如何查看上传的图片大小是否大于2MB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用php进行图像压缩。
<?phpif($ _POST){echo $ _FILES ['file'] [ '尺寸'];}>?< HTML> < head>< title> PHP代码压缩图片< / title>< / head> <身体GT; < form action =name =myformid =myformmethod =postenctype =multipart / form-data> < UL> <李> <标签>上传:其中/标签> < input type =filename =fileid =file/> < /锂> <李> < input type =submitname =submitid =submitclass =submit btn-success/> < /锂> < / UL> < /形式> < / body>< / html>
如果大小大于2MB,那么即使它在 $ _ FILES
中没有显示,也不会显示在图片小于2MB的图片上。 b 在提交按钮上
解决方案
您可以检查 $ _ FILES ['file'] ['error']
并检查它的值是否等于魔术常数 UPLOAD_ERR_INI_SIZE
if($ _FILES ['file'] ['error'] === UPLOAD_ERR_INI_SIZE){
//上传失败,因为大小限制
}
I am working on image compression in php.
<?php
if ($_POST) {
echo $_FILES['file']['size'];
}
?>
<html>
<head><title>Php code compress the image</title></head>
<body>
<form action="" name="myform" id="myform" method="post" enctype="multipart/form-data">
<ul>
<li>
<label>Upload:</label>
<input type="file" name="file" id="file"/>
</li>
<li>
<input type="submit" name="submit" id="submit" class="submit btn-success"/>
</li>
</ul>
</form>
</body>
</html>
This is working fine with the images less than 2MB.
if size>2MB then even its not showing in $_FILES
after clicking on the submit button
解决方案
You can check $_FILES['file']['error']
and check if it's value is equal to the magic constant UPLOAD_ERR_INI_SIZE
if ($_FILES['file']['error'] === UPLOAD_ERR_INI_SIZE) {
//uploading failed due to size limmit
}
这篇关于如何查看上传的图片大小是否大于2MB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文