简体   繁体   中英

laravel upload Can't write image data to path

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)

Code

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?

Solved

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 is public_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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM