2014-04-21 33 views
-1

當我嘗試使用laravel干預圖像庫保存圖像時,它可以正常工作,但擴展名缺失。Laravel干預圖像不返回擴展名

當我死了,並轉儲圖像的輸出::使()方法,我得到這個:

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 

正在上載有一個擴展但我不能訪問它,因爲它相信一個沒有按文件不存在。有任何想法嗎?

回答

7

介入影像醫生說:

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

所以建議的方式來利用爲「未知」也許原始數據後的圖像文件「默」:

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

當你上傳與PHP文件,他們被重新命名爲這樣的/tmp/phpJHlKbK,所以沒有可用的擴展。

但是干預圖像2.0(上週發佈)會在保存時檢查MIME類型(如果沒有可用的擴展名)。