[英]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.
我总是传递给jpg类型的这个函数图像,但是当我传递带有“.jpg”扩展名的图像时会出现问题。 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
但是当我尝试获取它的mime类型时,我发现它的“ application / octet-stream ”..在这个php页面中 ,这个mime类型指的是其中一个
IMAGETYPE_JPC,IMAGETYPE_JPX,IMAGETYPE_JB2 IMAGETYPE_JPC,IMAGETYPE_JPX,IMAGETYPE_JB2
what I need to modify my function to handle this mime type ?? 我需要修改我的函数来处理这个mime类型?
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";
}
}
I'm working around the same thing just now. 我刚才正在做同样的事情。
I was testing some images, .gif, .jpeg, .png ... using finfo
I found the mime-type you read depends on the constants you use to read the file. 我正在测试一些图像,.gif,.jpeg,.png ...使用
finfo
我发现你读取的mime类型取决于你用来读取文件的常量。 More! 更多! You read application/octet-stream as mimetype from images!
您可以从图像中读取application / octet-stream作为mimetype! and that info is not wrong.
并且该信息没有错。 See:
看到:
If you use finfo_open() without constants: 如果你使用没有常量的finfo_open():
<?php
$finfo = finfo_open();
$FileInfo = finfo_file($finfo, $tmp_name);
finfo_close($finfo);
You get the mime type you expect: 你得到了你期望的mime类型:
If .svg -> HTML document, ASCII text, with very long lines, with no line terminators
如果.svg - > HTML文档,ASCII文本,行很长,没有行终止符
If .jpg (from your phone camera) -> JPEG image data, EXIF standard 2.2
如果.jpg(来自您的手机摄像头) - > JPEG图像数据,EXIF标准2.2
If .gif (saved from paint) -> GIF image data, version 89a, wxh
如果.gif(从油漆中保存) - > GIF图像数据,版本89a,wxh
while using a constant like FILEINFO_MIME_TYPE 同时使用像FILEINFO_MIME_TYPE这样的常量
<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE, $mf); // $mf is a magic file
$FileInfo = finfo_file($finfo, $tmp_name);
finfo_close($finfo);
you got a different value: 你有不同的价值:
if .svg -> text/plain
if .svg - > text / plain
if .jpg (from your phone camera) -> application/octet-stream
如果.jpg(来自手机摄像头) - > application / octet-stream
if .gif (saved from paint) -> application/octet-stream
if .gif(从paint中保存) - > application / octet-stream
So you must test what you read when testing mimetypes. 所以你必须测试你在测试mimetypes时读到的内容。 See Fileinfo Predefined constants
请参阅Fileinfo预定义常量
Hope it helps 希望能帮助到你
We can't tell you because application/octet-stream
is a sort of general-type-of-binary-file mime-type. 我们无法告诉你,因为
application/octet-stream
是一种通用类型的二进制文件mime-type。 It can be everything. 它可以是一切。 You can try with
imagecreatefromstring
on the files binary content. 您可以在文件二进制内容上尝试使用
imagecreatefromstring
。 But keep fingers crossed ;). 但保持手指交叉;)。
The actual issue here is that getimagesize
is independent to the GD library you use for resizing the image. 这里的实际问题是
getimagesize
独立于用于调整图像大小的GD库。 So it provides infos about files GD itself is not able to deal with. 所以它提供了关于GD本身无法处理的文件的信息。 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: 另见:
In the case of application/octet-stream, You could get the original file name and check its extension. 对于application / octet-stream,您可以获取原始文件名并检查其扩展名。 If its jpg you should be good to go
如果它的jpg你应该很高兴去
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.