This article mainly introduces PHP to get the header information to determine the type of image, involving PHP related to the image file of the operation skills, the need for friends can refer to the following
In this paper, we describe how PHP determines the type of the image by acquiring the header information. Share to everyone for your reference. The implementation method is as follows:
$filename = ' 617.gif '; function Pictype ($file) {/ * $png _header = "/x89/x50/x4e/x47/x0d/x0a/x1a/x0a"; $jpg _header = "/xff/xd8"; * /$header = file_get_contents ($file, 0, NULL, 0, 5); echo Bin2Hex ($header); if ($header {0}. $header {1}== "/x89/x50") { return ' png '; } else if ($header {0}. $header {1} = = "/xff/xd8") { return ' JPEG '; } else if ($header {0}. $header {1}. $header {2} = = "/x47/x49/x46") { if ($header {4} = = "/x37") re Turn ' gif87 '; else if ($header {4} = = "/x39") return ' gif89 '; }} Echo Pictype ($filename);