Laravel 干预图像不返回扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23199468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel intervention image not returning an extension
提问by Mike
When I try to save an image using the intervention image library with laravel it works however the extension is missing.
当我尝试使用带有 laravel 的干预图像库保存图像时,它可以工作,但是缺少扩展名。
When I die and dump the output of the Image::make() method I get this:
当我死了并转储 Image::make() 方法的输出时,我得到了这个:
object(Intervention\Image\Image)[304]
public 'resource' => resource(9, gd)
public 'type' => int 2
public 'width' => int 480
public 'height' => int 640
public 'dirname' => string '/tmp' (length=4)
public 'basename' => string 'phpJHlKbK' (length=9)
public 'extension' => null
public 'filename' => string 'phpJHlKbK' (length=9)
public 'mime' => string 'image/jpeg' (length=10)
protected 'original' => null
public 'encoded' => null
The file that is being uploaded has an extension yet I cannot access it as it believes one doesn't exist. Any ideas?
正在上传的文件有一个扩展名,但我无法访问它,因为它认为一个不存在。有任何想法吗?
回答by jeepmac
Intervention Image doc says:
干预图像文档说:
The current filename extension of the image file, if instance was created from file.
So suggested way to utilize 'mime' for 'unknown' maybe Raw post data image files:
因此,建议将“mime”用于“未知”的方法可能是原始发布数据图像文件:
$mime = $image->mime(); //edited due to updated to 2.x
if ($mime == 'image/jpeg')
$extension = '.jpg';
elseif ($mime == 'image/png')
$extension = '.png';
elseif ($mime == 'image/gif')
$extension = '.gif';
else
$extension = '';
回答by Meinama
When you're uploading files with PHP, they are renamed to something like this /tmp/phpJHlKbK
, so there is no extension available.
当您使用 PHP 上传文件时,它们会被重命名为类似的名称/tmp/phpJHlKbK
,因此没有可用的扩展名。
However Intervention Image 2.0 (which was released last week) checks for the MIME type if no extension is available, while saving.
但是,Intervention Image 2.0(上周发布)会在保存时检查 MIME 类型(如果没有可用扩展名)。