Изображение вмешательства не может записать в storage_path - PullRequest
0 голосов
/ 22 февраля 2019

Я хочу сохранить загруженное изображение в storage_path (storage / app / images / users), а не public_path (public / images / users) в моем приложении Laravel.

Моя конфигурация файловой системы следующая:

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

    'users'=> [
        'driver' => 'local',
        'root' => storage_path('app/images/users'),
        'url' => env('APP_URL').'/storage'
    ],

    's3' => [
        'driver' => 's3',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'region' => env('AWS_DEFAULT_REGION'),
        'bucket' => env('AWS_BUCKET'),
        'url' => env('AWS_URL'),
    ],

],

Я также создал необходимые папки по нужному пути.

Мой скрипт загрузки выглядит следующим образом:

 public function upload_avatar($data) 
{

    $users_image_location=storage_path('images/users');
    $users_image_thumb_location_1=storage_path('images/users/thumbs-100');
    $users_image_thumb_location_2=storage_path('images/users/thumbs-50');
    $users_image_thumb_location_3=storage_path('images/users/thumbs-30');

    $image = $data['photo'];

    $filename = User::create_random_name(32) . '.' . $image->extension();

    $image_file = Image::make($image->getRealPath());

    list($width, $height) = getimagesize($image);

    if ($width > 700) 
    {
        //Resize the image
        $image_file->resize(600, 600, function ($constraint) {
            $constraint->aspectRatio();
        });            
    } 
    //save the image file
    $image_file->save($users_image_location.'/' . $filename);

    //create and store a 100px thumbnail of the image
    $image_file->resize(100, 100, function($constraint) {
        $constraint->aspectRatio();
    })->save($users_image_thumb_location_1.'/'.$filename);

    $image_file->resize(50, 50, function($constraint) {
        $constraint->aspectRatio();
    })->save($users_image_thumb_location_2.'/'.$filename);

    $image_file->resize(30, 30, function($constraint) {
        $constraint->aspectRatio();
    })->save($users_image_thumb_location_3.'/'.$filename);

    //return the filename of the image
    return $filename;
}

Но когда я его запускаю, я получаюследующее исключение, указывающее, что система не может записать в путь.

Невозможно записать данные изображения в путь (C: \ xampp \ htdocs \ NelpritadConcept \ storage \ images / users / NITA5VYtiWGSbWLmy2M6mtTpbW6XyupA.jpeg)

и при изменениипути public_path () выглядят следующим образом:

    $users_image_location=public_path('images/users');
    $users_image_thumb_location_1=public_path('images/users/thumbs-100');
    $users_image_thumb_location_2=public_path('images/users/thumbs-50');
    $users_image_thumb_location_3=public_path('images/users/thumbs-30');

работает как положено.

Я использую Laravel 5.7, PHP 7.2 на ОС Windows 10, Apache

Я хочучтобы узнать, как я могу хранить свои изображения в папке хранения вместо публичного пути.

Буду признателен за любые инструкции по выполнению этой операции С уважением

...