kur*_*ter 5 php image intervention laravel-5.3
我正在尝试使用 Intervention 来调整图像大小,然后将其保存在我定义的磁盘中,但我无法让它工作。使用 public_folder 将其保存在我的应用程序根目录中名为 /public 的文件夹中。
我创建了一个新磁盘
'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',
],
Run Code Online (Sandbox Code Playgroud)
我需要接受用户的输入,然后将他们上传的文件保存到该磁盘,然后将文件路径保存到数据库。
$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();
Run Code Online (Sandbox Code Playgroud)
我想最终得到类似于应该发生的事情
$fieldValue = $fieldFile->store($fieldName, 'images');
Run Code Online (Sandbox Code Playgroud)
该文件应结束于
/path/to/laravel/storage/app/public/images/
Run Code Online (Sandbox Code Playgroud)
稍后,如果我将图像磁盘更改为 s3 或其他位置,我希望此代码继续运行。
小智 7
您需要像这样对图像进行编码
$fieldFile = $request->file($fieldName);
$mime= $fieldFile->getClientOriginalExtension();
$imageName = time().".".$mime;
$image = Image::make($fieldFile)->crop(350, 350)
Storage::disk('public')->put("images/".$imageName, (string) $image->encode());
Run Code Online (Sandbox Code Playgroud)
$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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5214 次 |
| 最近记录: |