在上传图片php之前获取图片大小 [英] get image size before upload image php
本文介绍了在上传图片php之前获取图片大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道mb中的图像大小,但在ulpload做同样的事情之前。
我有:
$ errors = array();
$ image = $ _FILES ['image'] ['name'];
$ file_tmp = $ _FILES ['image'] ['tmp_name'];
$ image_type = $ _FILES ['image'] ['type'];
$ descricao = $ _POST ['descricao'];
if(empty($ image)|| $ _FILES ['image'] ['size']> = 1000)
{
$ _SESSION ['alert_type'] = -1;
$ _SESSION ['msg_alert'] =imagem did not upload!;
}
其他
{
//上传
}
问题是知道文件大小,$ _FILES ['image'] ['size']不能正常工作。
谢谢
解决方案
$ file_tmp = $ _FILES ['image'] ['tmp_name'];
$ size = filesize($ file_tmp);
但是您是否意识到您希望图像在代码示例中小于千字节? / p>
I want to know the image size in mb but before ulpload do the same. I have:
$errors = array();
$image = $_FILES['image']['name'];
$file_tmp = $_FILES['image']['tmp_name'];
$image_type = $_FILES['image']['type'];
$descricao = $_POST['descricao'];
if(empty($image) || $_FILES['image']['size'] >= 1000)
{
$_SESSION['alert_type'] = -1;
$_SESSION['msg_alert'] = "imagem didnt upload!";
}
else
{
//upload
}
The problem is to know the file size, the $ _FILES ['image'] ['size'] is not working well. thanks
解决方案
Before upload you can check like so:
$file_tmp = $_FILES['image']['tmp_name'];
$size = filesize($file_tmp);
But do you realize you are expecting the image to be less than a kilobyte in your code example?
这篇关于在上传图片php之前获取图片大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文