Laravel干预图像未返回扩展名 [英] Laravel intervention image not returning an extension

查看:57
本文介绍了Laravel干预图像未返回扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用带有laravel的干预图像库保存图像时,它可以工作,但是扩展名丢失.

When I try to save an image using the intervention image library with laravel it works however the extension is missing.

当我死掉并转储Image :: make()方法的输出时,我得到了:

When I die and dump the output of the Image::make() method I get this:

  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?

推荐答案

干预图像文档说:

The current filename extension of the image file, if instance was created from file.  

因此建议将"mime"用于未知"(也许是原始帖子数据图像文件)的方法:

So suggested way to utilize 'mime' for 'unknown' maybe Raw post data image files:

$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 = '';

这篇关于Laravel干预图像未返回扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆