Juan Carlos Aduan
Juan Carlos Aduan

Reputation: 73

how to know if a file picture or not using getimagesize function

<form action = "index.php" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "image_name" /><input type = "submit" value = "Upload" name = "upload"/>
</form>

<?php 
include("connect.php");

   if(isset($_POST['upload'])){
     $file = file_get_contents($_FILES['image_name']['tmp_name']);
     $name = $_FILES['image_name']['name'];
     $image_size = getimagesize($_FILES['image_name']['tmp_name']);

   if($image_size == false){
    echo "Thats not an image.";
}

}
?>

There is an error that appears. How can I avoid the error notice?

Here is the error message:

Notice: getimagesize() [function.getimagesize]: Read error! in C:\xampp\htdocs\picture\index.php on line 16

Upvotes: 1

Views: 191

Answers (1)

quietmint
quietmint

Reputation: 14153

Use @getimagesize to suppress the notice. An error is the expected behavior if the file can't be read as an image.

See PHP: Error Control Operators for more information about the @ operator.

Upvotes: 3

Related Questions