2017-02-26 29 views
3

我試圖使用干預來調整圖像大小,然後將其保存在我定義的磁盤中,但我無法使其工作。使用public_folder將其保存在名爲/ public的應用程序根目錄中的文件夾中。Laravel干預在特定磁盤中保存圖像

我創建了一個新的磁盤

'disks' => [ 

    'local' => [ 
     'driver' => 'local', 
     'root' => storage_path('app'), 
    ], 

    'public' => [ 
     'driver' => 'local', 
     'root' => storage_path('app/public'), 
     'visibility' => 'public', 
    ], 

    'images' => [ 
     'driver' => 'local', 
     'root' => storage_path('app/public/images'), 
     'visibility' => 'public', 
    ], 

,我需要接受來自用戶的輸入,然後自己上傳的文件,那麼文件路徑保存到磁盤,到數據庫。

$fieldFile = $request->file($fieldName); 
$imageName = time(); 
Image::make($fieldFile)->crop(350, 350)->save(public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension()); 
$object->$fieldName = public_path() . '/' . $imageName . '.' . $fieldFile->getClientOriginalExtension(); 

我想用類似於從

$fieldValue = $fieldFile->store($fieldName, 'images'); 

應該發生什麼事結束了該文件應在

/path/to/laravel/storage/app/public/images/ 

結束以後,如果我改變圖像盤到s3或其他地方,我希望這個代碼繼續運作。

回答

0
$fieldFile = $request->file($fieldName); 
//$imageName = time(); 

$mime= $fieldFile->getClientOriginalExtension(); 
$imageName = time().".".$mime; 
$image = Image::make($fieldFile)->crop(350, 350) 

$location = Storage::disk('images')->put($imageName, $image); 
//images can be substituted for any disk local or s3 etc. 
+0

不適合我。 – Turtle