2014-04-21 3 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

개입 이미지 문서는 말한다 : 당신이 PHP로 파일을 업로드 할 때

$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

:

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

그래서 제안 방법은 '알 수없는'어쩌면 원시 데이터 후 이미지 파일 '마임'을 활용 , 그들은 /tmp/phpJHlKbK과 같은 이름으로 바뀌므로 확장자가 없습니다.

그러나 Intervention Image 2.0 (지난 주 발표 됨)은 저장하는 동안 확장자가 없으면 MIME 형식을 확인합니다.

관련 문제