Home >>Advance PHP Tutorial >Check image extension before uploading

Check image extension before uploading



Check image extension before uploading a image

<?php

	$supported_image = array('gif','jpg','jpeg','png');

   $src_file_name = 'abskwlfd.png';

   $ext = strtolower(pathinfo($src_file_name, PATHINFO_EXTENSION));

      //echo $ext; 
	// Using strtolower to overcome case sensitive

	if (in_array($ext, $supported_image))

	 {

	   echo "it's image";

	 }

	else 

	{

	   echo 'not image';

	}

    ?>

Output it's image