Tags
PHP
Asked 8 years ago
6 Oct 2016
Views 808
sarah

sarah posted

how to Checks if the file is an image in php ?

How to check the file is image or in other format in php .

i tried to explode filename with "."(dot) but try to compare with extension .png or .jpg but some time more than one (dot). in the file name so i need easy code with regex so it full proof checking without any backside in php

Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

following function will return true if it image file which should be one of the extension from xcf,odg,gif,jpg,png,bmp


	 
	function CheckisImage( $fileName )
	{
		  $imageTypes = 'xcf|odg|gif|jpg|png|bmp';
		return preg_match("/$imageTypes/i",$fileName);
	}
Post Answer