使用PHP上传图片前检查图片的尺寸(高度和宽度) [英] Check image dimensions (height and width) before uploading image using PHP
问题描述
我必须先上传图片并使用getimagesize()吗?或者可以在使用PHP上传之前检查它?
<?php
foreach($ (
$错误== UPLOAD_ERR_OK
&& $ _FILES [files)[_FILES [files] [error] as $ key => $ error) ] [size] [$ key]< 500000
&& $ _FILES [files] [type] [$ key] ==image / gif
|| $ _FILES [files] [type] [$ key] ==image / png
|| $ _FILES [files] [type] [$ key] ==image / jpeg
|| $ _FILES [files] [type] [$ key] ==image / pjpeg
){
$ filename = $ _FILES [files] [name] [$ key];
$ b(如何检查宽度和高度)
{
echo'< p>图片尺寸必须小于1000px宽度和1000px高度;
}
}
?>
实际上传发生。 How can I check for height and width before uploading image, using PHP. Must I upload the image first and use "getimagesize()"? Or can I check this before uploading it using PHP?
You need something that is executed on the client before the actual upload happens. So your options are flash, maybe html5 with its FileAPI (haven't tested that, maybe that's not doable), java-applet, silverlight, ... 这篇关于使用PHP上传图片前检查图片的尺寸(高度和宽度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
使用(服务器端)PHP,您可以检查维度只有在文件上传后或与 / em> / em-php-v525 /rel =nofollow所以你的选择是闪存,也许HTML5与其FileAPI(没有测试,也许这是不可行的),Java的小程序,silverlight,... p> <?php
foreach ($_FILES["files"]["error"] as $key => $error) {
if(
$error == UPLOAD_ERR_OK
&& $_FILES["files"]["size"][$key] < 500000
&& $_FILES["files"]["type"][$key] == "image/gif"
|| $_FILES["files"]["type"][$key] == "image/png"
|| $_FILES["files"]["type"][$key] == "image/jpeg"
|| $_FILES["files"]["type"][$key] == "image/pjpeg"
){
$filename = $_FILES["files"]["name"][$key];
if(HOW TO CHECK WIDTH AND HEIGHT)
{
echo '<p>image dimenssions must be less than 1000px width and 1000px height';
}
}
?>
With (server-side) php you can check the dimension only after the file has been uploaded or with upload hooks maybe while the image is uploaded (from the image file header data).