PHP : binary image data, checking the image type

前端 未结 7 1591
刺人心
刺人心 2020-11-30 02:44

I have some images in bin, I want to check the header to check the format (jpg, png, etc)

I don\'t want to use temp files! I have a solution using TEMP FILES.

7条回答
  •  盖世英雄少女心
    2020-11-30 03:31

    Use the fileinfo PHP extension:

    http://de.php.net/manual/en/function.finfo-file.php

    Its using the "file" *nix command to reliably determine the mime-type of a given file:

    $finfo = finfo_open(FILEINFO_MIME_TYPE); 
    $mimetype = finfo_file($finfo, $filename);
    finfo_close($finfo);
    

    This extension is shipped with PHP 5.3 or can be installed from pecl (pecl install fileinfo) for earlier versions.

提交回复
热议问题