Horje
How to check Image error or valid in PHP

Use getimagesize() it will return FALSE if file corrupt otherwise if file is ok then it will return array containing file info like mime, height and width etc , try below example


Check Image is Valid

Here runs following code to Check Image is Valid
index.php
Example: PHP
<?php $fileName = 'https://horje.com/avatar.png'; //filepath if(getimagesize($fileName) === false){ echo "Image is corrupted"; } else{ echo "Image is ok"; }
?>

Output should be:

Check Image is Valid

Check Image is corrupted

Here runs following code to Check Image is corrupted
index.php
Example: PHP
<?php $fileName = 'https://horje.com/efeff.png'; //filepath if(getimagesize($fileName) === false){ echo "Image is corrupted"; } else{ echo "Image is ok"; }
?>

Output should be:

Check Image is corrupted





Category :
Web Tutorial
Sub Category :
PHP Image Tutorial
Uploaded by :
Admin