我正在尝试保存经过处理的图像,我会将其推送到 s3。
我的代码有效此代码将图像直接保存在公共(public)文件夹中*
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());
}
}
我想要实现的是能够将它保存在它自己的文件夹中。首先,在 public 文件夹的 storage 中,什么是存储博客文章图像的最佳位置?但无论如何,当我这样做时:
$image->save('blogpost/' . $postId . '/' . $file->getClientOriginalName());
// Or this
$image->save(storage_path('app/blogpost/' . $postId . '/' . $file->getClientOriginalName()));
我得到错误:
folder within public
NotWritableException in Image.php line 138: Can't write image data to path (blogpost/146/cars/image.jpg)
or
storage path
NotWritableException in Image.php line 138: Can't write image data to path /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)));
这有效
关于php - 无法保存图像干预图像。 Image.php 第 138 行中的 NotWritableException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31198379/