如何檢查圖片上傳後的圖片尺寸,如果圖片尺寸與我想要的尺寸不匹配,則將其刪除 ?PHP Image Upload檢查尺寸
因此,經過挖掘,我發現PHP不能做尺寸。我下面的解決方案是:
- 將文件上傳到服務器
- 使用新的字符串和檢查
- 刪除或繼續上傳,如果它 不匹配的寬度和高度
這是我的代碼。有人能告訴我如何檢查當前文件的尺寸以及如何刪除文件夾和文件,如果不匹配?
# create our temp dir
mkdir("./uploads/temp/".$user."/".$mx."/".$hash."/", 0777, true);
# upload dir settup
$uploaddir='./uploads/temp/'.$user.'/'.$mx.'/'.$hash.'/';
$file=$uploaddir . basename($_FILES['file']['name']);
# upload the file first
if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) {
# ok so check the height and width
# if it is not the width and height assigned delete image and folder
if (image height= and width =){
unlink($file);
rmdir($uploaddir);
$result=0;
} else {
# image matches height and width message ok
$result=1;
}
} else {
# error uploading
$result=$errormsg;
}
請編輯您的帖子開頭解釋你在做什麼試圖去做。不要讓我們試圖弄清楚你的目標是什麼。 – 2012-02-16 19:36:54
你是什麼意思_So挖掘後我發現PHP不能做dimensions_?那麼'getimagesize()'http://php.net/manual/en/function.getimagesize.php – elclanrs 2012-02-16 19:38:30
編輯..我不知道getimagesize - 它不會刪除圖像文件夾。你能告訴我一個例子嗎? – TheBlackBenzKid 2012-02-16 19:39:17