我使用jquery-filedrop并且我只允许用户上传文件 PNG & JPG
但是如何检查图像大小(如像素)?
可以在文件对象中获取图像大小吗?
在我查看了 console.log 中的文件对象之后,它与图像大小无关。
或者我必须检查 PHP 或附加图像所以.width()
& .height()
(REF)?
我使用jquery-filedrop并且我只允许用户上传文件 PNG & JPG
但是如何检查图像大小(如像素)?
可以在文件对象中获取图像大小吗?
在我查看了 console.log 中的文件对象之后,它与图像大小无关。
或者我必须检查 PHP 或附加图像所以.width()
& .height()
(REF)?
根据Georg Schölly的回答:
// find the element
var img = $('#imageid');
/*
* create an offscreen image that isn't scaled
* but contains the same image.
* Because it's cached it should be instantly here.
*/
var theImage = new Image();
theImage.src = img.attr("src");
// you should check here if the image has finished loading
// this can be done with theImage.complete
alert("Width: " + theImage.width);
alert("Height: " + theImage.height);
好的,我这样发布到 PHP
$size = getimagesize($_FILES['name']['tmp_name']);
if($size[0]===150 && $size[1]===150) {
// done
} else {
// error
}