How to handle image mime type "application / octet-stream"?

I have a function to sketch a URL image on the fly! I always go to these image functions using the jpg type, but the problem occurs when I pass the image with the ".jpg" extension. but when i try to get its mime type i found that " application / octet-stream " .. in this php page this mime type refers to one of


what do I need to change my function to handle this mime type?

notification ^^^^^^

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');
        else if ($file_type=='application/octet-stream')
           // ^^^^^ what I should write here
            echo "Not supported type";



source to share

2 answers

We cannot tell you because is application/octet-stream

is a general-type-of-of-binary-file mime-type type. It could be anything. You can try with imagecreatefromstring

in binary content files. But keep your fingers crossed;).

The real problem here is that it getimagesize

doesn't depend on the GD library you are using to resize the image. Thus, it provides information about files that GD itself cannot handle. So you can just infer some "unsupported image type" until you find some additional library capable of handling a particular mime- or better say type.

See also:



In the case of an app / octet stream, you can get the original filename and check its extension. If its a jpg you should be kind to go



All Articles