My application is having images sent to it from mobile devices with the content-type \"application/octet-stream\".
I need to process these images using the GD librar
I found this in the codeigniter forum a way to change the mime and it works, I suppose you can use for other frameworks as well, this is the link and this the code:
//if mime type is application/octet-stream (psp gives jpegs that type) try to find a more specific mime type
$mimetype = strtolower(preg_replace("/^(.+?);.*$/", "\\1", $_FILES['form_field'] ['type'])); //reg exp copied from CIs Upload.php
if($mimetype == 'application/octet-stream'){
$finfo = finfo_open(FILEINFO_MIME, '/usr/share/file/magic');
if($finfo){
$_FILES['form_field']['type'] = finfo_file($finfo, $_FILES['form_field']['tmp_name']);
finfo_close($finfo);
}
else echo "finfo_open() returned false");
}
Fileinfo extension needs to be installed on the server.
It worked for me.
Easy :)
$image = imagecreatefromstring( $data );
Specifically:
$data = file_get_contents($_FILES['myphoto']['tmp_name']);
$image = imagecreatefromstring( $data );
you can use this function too. it not require any other dependency. and work perfectly for other types also.
function _getmime($file){
if($info = @getimagesize($file)) {
return image_type_to_mime_type($info[2]);
} else {
return mime_content_type($file);
}
}