strange image php validation
i have this script for an image validation. works fine with images with 500 kb or 1.5 mb for example, but if i try with images with 4mb or 6 for example, give the error Invalid format and no开发者_如何学Ct the "size large". Why?
$imageData = @getimagesize($_FILES["userfile"]["tmp_name"]);
if($imageData === FALSE || !($imageData[2] == IMAGETYPE_GIF || $imageData[2] == IMAGETYPE_JPEG || $imageData[2] == IMAGETYPE_PNG)) {
echo "<li>Invalid format</li>";
die();
}
else {
if($_FILES["userfile"]["size"] >= 2000000) {
echo "<li>The size large</li>";
die();
}
else {
//mystuff
}
thanks
You might also want to check your post_max_size and upload_max_filesize in php.ini. If the files you are trying to upload are too large, then I believe the _FILES array will not be populated.
You're not checking if the file upload succeeded. PHP has a memory limit which applies to uploaded files, and your 'big' images are most likely over that limit. You should check the uploads like this:
if ($_FILES['userfile']['error'] === UPLOAD_ERR_OK) {
... uploaded ok ...
} else
echo "File upload failed on 'userfile' with error: " . $_FILES['userfile']['error'];
}
use $_FILES['size'] .. getimagesize is extremely slow for large images
精彩评论