无法保存图像干预图像。 Image.php第138行中的NotWritableException [英] Cannot save image intervention image. NotWritableException in Image.php line 138
问题描述
我试图保存一个被操纵的图像,我将它们推送到s3。
我的代码有效此代码将图像直接保存在公共文件夹中*
公共函数存储(Filesystem $ filesystem)
{
$ request = Input :: all();
$ validator = Validator :: make($ request,[
'images'=>'image'
]);
if($ validator-> failed()){
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());
}
}
我想做什么喜欢实现的是能够将它保存在自己的文件夹中。首先,在公共文件夹的存储中,为博客帖子存储图像的最佳位置是什么?但无论如何,当我这样做时:
$ image-> save('blogpost /'。$ postId。'/'。 $文件 - > getClientOriginalName());
//或者这个
$ image-> save(storage_path('app / blogpost /'。$ postId。'/'。$ file-> getClientOriginalName( )));
我收到错误:
$公共区域内的b $ b文件夹
Image.php第138行中的NotWritableException:无法将图像数据写入
路径(blogpost / 146 / cars / image.jpg)
或
存储路径强>>
Image.php第138行中的NotWritableException:无法将图像数据写入
path / code / websites / blog / storage / app / blogpost / 146 / image.jpg
我试过
cd storage / app /
chmod -R 755 blogpost
它仍然无法工作
感谢您阅读本文
Ok所以这是我如何解决它,我在存储之前首先制作了目录,
存储::磁盘('本地') - > 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)));
此工作
Im trying to save a manipulated image which i will them push to s3.
My code that works This code saves the image directly within the public folder*
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());
}
}
What i would like to achieve is to be able to save it within a folder of it's own. Firstly what is the best place to store an image for a blog post, within the storage of public folder? But anyway when i do this:
$image->save('blogpost/' . $postId . '/' . $file->getClientOriginalName());
// Or this
$image->save(storage_path('app/blogpost/' . $postId . '/' . $file->getClientOriginalName()));
I get the error:
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
I've tried
cd storage/app/
chmod -R 755 blogpost
And it still wont work
Thank you for reading this
Ok so here is how i solved it, I made the directory first before storing,
Storage::disk('local')->makeDirectory('blogpost/' . $postId);
Once the folder is created i then go on to store the manipulated images like so:
$image->save(storage_path('app/blogpost/' . $postId . '/' . $imageName));
And then pushing the image to S3
$filesystem->put('blogpost/' . $postId . '/' . $imageName, file_get_contents(storage_path('app/blogpost/' . $postId . '/' . $imageName)));
This worked
这篇关于无法保存图像干预图像。 Image.php第138行中的NotWritableException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!