确定缺少扩展名的图像的文件扩展名


Determine file extension of an image that is missing an extension

我的系统上有一些图像在没有文件扩展名的情况下保存,它们以"文件名"的格式显示。(注意句点)

我正在尝试使用 getimagesize(); 但它错误地告诉我"文件名不能为空"

这是我正在使用的代码示例

    $contents = file_get_contents($localFile);
    $imageData = getimagesize($contents);
    // $imageData[2] will contain the value of one of the constants
    $mimeType = image_type_to_mime_type($imageData[2]);
    $extension = image_type_to_extension($imageData[2]);

查看文档: http://php.net/getimagesize
getimagesize() 需要文件名作为第一个参数,而不是图像文件的内容。

尝试:

$imageData = getimagesize($localFile);
// $imageData[2] will contain the value of one of the constants
$mimeType = image_type_to_mime_type($imageData[2]);
$extension = image_type_to_extension($imageData[2]);

getimagesize需要文件名作为第一个参数