I’m trying to check an images size in PHP but I’m getting a couple errors. I can save the image and view it, but if I add in a function to check it’s size I get an error.
Warning: imagesx() expects parameter 1 to be resource, array given in...
Warning: imagesy() expects parameter 1 to be resource, array given in...
here’s what I use to check the size/upload
if(isset($_POST['submitImage'])){
$image = new imageProcessing;
$image->checkSize($_FILES["image"]);
}
Here is the HTML
?>
<h2>Upload Profile Image</h2>
<form action="editinfo.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="image" id="file" /> <br />
<input type="submit" name="submitImage" value="Submit" />
</form>
And here is the function to check size
function checkSize($image){
if(imagesx($image) > 100 OR imagesy($image) > 100){
echo "too large";
}
}
Using getimagesize as DrAgonmoray suggested, I get the following error
Warning: getimagesize() expects parameter 1 to be string, array given in...
$_FILES provides an ARRAY of information PER FILE you upload. This array contains the path to the temporary file that PHP has stored the file in. It’s THAT temporary filename you need to use. As well, imagesx() and imagesy() do not accept filenames as their parameters. They expect a GD resource handle. So your code is broken on multiple levels.