How can the getimagesize() function be utilized in PHP to determine the type of an image file?
To determine the type of an image file in PHP, you can use the getimagesize() function. This function returns an array containing the image width, height, type, and attributes. By checking the value of the 'mime' key in the returned array, you can determine the type of image file.
$image_path = 'image.jpg';
$image_info = getimagesize($image_path);
$image_type = $image_info['mime'];
echo "The image type is: " . $image_type;
Related questions
-
array sorting multi-column sorting usort
-
Syntax error Parse Error PHP code
-
Sanitize Validation Cross-site scripting (XSS)