2017-02-26 60 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