如何处理图像的mime类型"application/octet-stream"?

use*_*363 5 php thumbnails gd2 mime-types

我有一个功能,可以在飞行中制作网址图片缩略图!我总是传递给jpg类型的这个函数图像,但是当我传递带有".jpg"扩展名的图像时会出现问题.但是当我尝试获取它的mime类型时,我发现它的" application/octet-stream "..在这个php页面中,这个mime类型指的是其中一个

IMAGETYPE_JPC,IMAGETYPE_JPX,IMAGETYPE_JB2

我需要修改我的函数来处理这个mime类型?

注意^^^^^^

function thumb($path,$width,$height) // $path => image url
{
        $file_dimensions = getimagesize($path);
        $file_type = image_type_to_mime_type($file_dimensions[2]);
        list($Cwidth, $Cheight) = getimagesize($path);
        if ($file_type=='image/jpeg'||$file_type=='image/pjpeg'){
            // Load
        $thumb = imagecreatetruecolor($width, $height);
        $source = imagecreatefromjpeg($path);
        // Resize
        imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $Cwidth, $Cheight);
        header('Content-Type: image/jpeg');
        imagejpeg($thumb);
        }
        else if ($file_type=='application/octet-stream')
        {
           // ^^^^^ what I should write here
        }
        else
        {
            echo "Not supported type";
        } 
} 
Run Code Online (Sandbox Code Playgroud)

hak*_*kre 2

我们无法告诉您,因为application/octet-stream它是一种通用二进制文件 mime 类型。它可以是一切。您可以尝试使用imagecreatefromstring文件的二进制内容。但请祈祷;)。

这里的实际问题是,它getimagesize独立于您用于调整图像大小的 GD 库。因此它提供了有关 GD 本身无法处理的文件的信息。因此,您可以输出某种“不支持的图像类型”,直到找到一些能够处理特定 mime 或更好的图像类型的附加库。

另请参阅: