在php上传中有一种强制上传特定宽度和高度的方法,我有这个模块
if(Configuration::get('SHOW_IMAGES') == 1) {
$images = count($_FILES['images']['name']);
if ($images <= Configuration::get('MAX_IMAGES')) {
for ($i=1; $i<=Configuration::get('MAX_IMAGES'); $i++) {
if ($_FILES['images']['name'][$i] != "") {
if ((($_FILES['images']['type'][$i] == "image/pjpeg") ||
($_FILES['images']['type'][$i] == "image/jpeg") ||
($_FILES['images']['type'][$i] == "image/png")) &&
($_FILES['images']['size'][$i] < $this->return_bytes(ini_get('post_max_size')))) {
$url_images[$i] = $_FILES['images']['tmp_name'][$i];
}
else {
$this->errors[] = $this->module->l('The image format is incorrect or max size to upload is', 'addproduct').' '.ini_get('post_max_size');
}
}
else {
$this->errors[] = $this->module->l('The image is incorrect or max size to upload is', 'addproduct');
}
}
}
else {
$this->errors[] = $this->module->l('The maxim images to upload is', 'addproduct').' '.Configuration::get('MAX_IMAGES');
}
}
答案 0 :(得分:0)
使用getimagesize它将提供高度和宽度
list($width, $height, $type, $attr) = getimagesize($file["tmp_name"]);
if ($width == $minwidth && $height == $minheight)
{
echo "success";
}else
{
echo "error";
}
getimagesize()是php per-defined函数。这将确定任何给定图像文件的大小,并返回尺寸以及文件类型和高度/宽度。更多信息。 http://php.net/manual/en/function.getimagesize.php