Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how handling image's mime type "application/octet-stream"?

I have a function to make thumbnail of a url image on fly! I always pass to this functions images with type jpg, but the problem appears when I pass an image with ".jpg" extension. but when i try to get its mime type, i found that's "application/octet-stream" .. in this php page, this mime type refers to one of

IMAGETYPE_JPC,IMAGETYPE_JPX,IMAGETYPE_JB2

what I need to modify my function to handle this mime type ??

notice ^^^^^^

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";
        } 
} 
like image 598
user504363 Avatar asked Mar 14 '12 17:03

user504363


People also ask

What is MIME type application octet-stream?

The application/octet-stream MIME type is used for unknown binary files. It preserves the file contents, but requires the receiver to determine file type, for example, from the filename extension. The Internet media type for an arbitrary byte stream is application/octet-stream .

How do I decode an octet-stream?

You can't DECODE it to readable values without knowing which ENCODING was used. All you have is what TYPE the data is - not how it was ENCODED. You need to look at the Content-Encoding header (if there is one - if not, you need to ask the sender of the data how to decode it).

How do I change application octet-stream to application PDF?

Follow these Steps: In Octet-stream you will be receiving the response as "Encoded Binary Data" Your need to convert the response data into "Decoded Base64 String" Finally save it as PDF.


1 Answers

We can't tell you because application/octet-stream is a sort of general-type-of-binary-file mime-type. It can be everything. You can try with imagecreatefromstring on the files binary content. But keep fingers crossed ;).

The actual issue here is that getimagesize is independent to the GD library you use for resizing the image. So it provides infos about files GD itself is not able to deal with. So you can just output some sort of "unsupported image type" until you find some additional library that is able to deal with the specific mime- or better saying image-type.

See as well:

  • Android image file sent to php upload image file is application/octet-stream type and not image/jpeg?
  • Is it important to verify that the uploaded file is an actual image file?
like image 113
hakre Avatar answered Sep 18 '22 20:09

hakre