Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

file upload - Laravel intervention image not returning an extension

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

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

  object(InterventionImageImage)[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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...