我正在尝试保存经过处理的图像,并将其推送到 s3。
我的代码有效此代码将图像直接保存在公共文件夹中*
public function store(Filesystem $filesystem)
{
$request = Input::all();
$validator = Validator::make($request, [
'images' => 'image'
]);
if ($validator->fails()) {
return response()->json(['upload' => 'false']);
}
$postId = $request['id'];
$files = $request['file'];
$media = [];
$watermark = Image::make(public_path('img/watermark.png'));
foreach($files as $file) {
$image = Image::make($file->getRealPath());
$image->crop(730, 547);
$image->insert($watermark, 'center');
$image->save($file->getClientOriginalName());
}
}
我想要实现的是能够将其保存在它自己的文件夹中。首先,在博客文章中存储图像的最佳位置是什么?storage of public文件夹?但无论如何,当我这样做时:
$image->save('blogpost/' . $postId . '/' . $file->getClientOriginalName());
// Or this
$image->save(storage_path('app/blogpost/' . $postId . '/' . $file->getClientOriginalName()));
我收到错误:
公共文件夹内
Image.php 第 138 行中的 NotWritableException:无法将图像数据写入
路径(blogpost/146/cars/image.jpg)
or
存储路径
Image.php 第 138 行中的 NotWritableException:无法将图像数据写入
路径/code/websites/blog/storage/app/blogpost/146/image.jpg
我试过了
cd storage/app/
chmod -R 755 blogpost
但它仍然行不通
谢谢您阅读此篇
好的,这就是我解决它的方法,我在存储之前先创建了目录,
Storage::disk('local')->makeDirectory('blogpost/' . $postId);
创建文件夹后,我将继续存储操作后的图像,如下所示:
$image->save(storage_path('app/blogpost/' . $postId . '/' . $imageName));
然后将镜像推送到S3
$filesystem->put('blogpost/' . $postId . '/' . $imageName, file_get_contents(storage_path('app/blogpost/' . $postId . '/' . $imageName)));
这有效
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)