I just found a simple image upload script here on the forums, but I would like to modify it so that only an image of specific dimensions can be uploaded.
e.g 200×300 pixels.
[code=php]<?PHP
$uploaddir = “uploads/”; # must be chmoded to 777
if (isset($_POST[‘submit’])) {
$name = $_FILES[‘File’][‘name’];
$tmpname = $_FILES[‘File’][‘tmp_name’];
$size = $_FILES[‘File’][‘size’];
// If the user uploads not a valid image, then display an error msg.
$imgSize = @getImageSize($tmpname);
if (empty($imgSize)) {
print (“<p>Please upload a valid image.</p>n”);
} else {
/*** Get the mime type of the image and check, manager entered the valid image or not. ***/
$imageType = explode(“/”,$imgSize[‘mime’]);
$imageType = trim(strtolower($imageType[1]));
$validImageTypes = array(“jpg”, “jpeg”, “png”, “gif”); // you can also use the same code for checking other type of files like, PDF.
if (!in_array($imageType, $validImageTypes)) {
print(“<p>Please upload a valid image for cover.</p>n”);
} else {
if (move_uploaded_file($tmpname, $uploaddir . $name)) {
print (“<p>File Name: $name</p>n”);
print (“<p>File Size: $size</p>n”);
print (“<p>Your file was successfully uploaded!</p>n”);
} else {
print (“<p>Your file could not be uploaded.</p>”);
}
}
}
}
?>
Any ideas?