問題描述
如何在上傳圖片之前使用 PHP 檢查高度和寬度.
How can I check for height and width before uploading image, using PHP.
我必須先上傳圖像并使用getimagesize()"嗎?或者我可以在使用 PHP 上傳之前檢查這個嗎?
Must I upload the image first and use "getimagesize()"? Or can I check this before uploading it using PHP?
<?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';
}
}
?>
推薦答案
您需要在實際上傳發生之前在客戶端上執行某些操作.
使用(服務器端)php,您只能在文件上傳后或使用 upload hooks 可能在上傳圖像時(來自圖像文件頭數據).
You need something that is executed on the client before the actual upload happens.
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).
所以你的選擇是 flash,也許是帶有 FileAPI 的 html5(還沒有測試過,也許那不可行),java-applet,silverlight,...
So your options are flash, maybe html5 with its FileAPI (haven't tested that, maybe that's not doable), java-applet, silverlight, ...
這篇關于在使用 PHP 上傳圖像之前檢查圖像尺寸(高度和寬度)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!