9951 explained code solutions for 126 technologies


php-gdHow to get image type


$file = '/path/to/image';
$data = getimagesizefromstring(file_get_contents($file));
$type = $data['mime'];ctrl + c
$file

path to image of unknown type

getimagesizefromstring

returns image meta data from given string

file_get_contents

reads given file


Usage example

<?php

$file = '/path/to/image';
$data = getimagesizefromstring(file_get_contents($file));

echo $data['mime'];
output
image/jpeg