Reputation: 7128
I'm trying to store base64Image
with laravel but it returns this error:
Can't write image data to path (/home/u187504358/domains/example.com/public/images/Group-1590235658.jpg)
if ($request->photo) {
$photo = $request->photo;
$filename = 'Group' . '-' . time() . '.' . 'jpg';
$location = public_path('images/'. $filename);
Image::make(file_get_contents($photo))->resize(500, 500)->save($location);
$oldFilename = $group->photo;
if(!empty($group->photo)){
Storage::delete($oldFilename);
}
$group->photo = $filename;
}
filesystem.php
'default' => env('FILESYSTEM_DRIVER', 'local'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => public_path('images/'),
],
]
Any idea?
Upvotes: 0
Views: 103
Reputation: 7128
I've added this code to my index.php
file in public aka public_html
folder and it works now
$app->bind('path.public', function() {
return __DIR__;
});
Note: As you see in error it tries to connect with folder
public (domains/example.com/public/images)
but in server (shared host) there ispublic_html
folder. So it made me think twice that laravel tries to connect to the wrong path and code above solved the issue.
-Hope it help others.
Upvotes: 1