Mik*_*ike -1 file-upload image laravel
当我尝试使用具有laravel的干预图像库来保存图像时,它可以工作,但是缺少扩展.
当我死了并转储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
Run Code Online (Sandbox Code Playgroud)
正在上传的文件有一个扩展名但我无法访问它,因为它认为一个文件不存在.有任何想法吗?
干预图像文档说:
The current filename extension of the image file, if instance was created from file.
Run Code Online (Sandbox Code Playgroud)
因此建议使用'mime'作为'未知'的方法可能是Raw post数据图像文件:
$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 = '';
Run Code Online (Sandbox Code Playgroud)