Laravel storage link won't work on production

2020-03-27 11:29发布

I'm using storage_path to save my images and I symbolic my storage folder to public_html

php artisan storage:link

On the local everything works fine, when I upload an image it will upload in storage folder and link of it will appear in public folder but since I moved to live host and production mode my images will upload in storage folder but nothing in my public_html/storage and I'm not able to get them in my front-end.

Codes

/config/filesystems.php

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

.env

FILESYSTEM_DRIVER=public

controller sample

if ($request->hasFile('image')) {
  $image = $request->file('image');
  $filename = 'page' . '-' . time() . '.' . $image->getClientOriginalExtension();
  $location = storage_path('app/public/images/' . $filename);
  Image::make($image)->resize(1200, 600)->save($location);
  if(!empty($page->image)){
    Storage::delete('images/' . $page->image);
  }
  $page->image = $filename;            
}

any idea?

标签: php laravel
7条回答
三岁会撩人
2楼-- · 2020-03-27 12:07

I see that the question has been answered but I want to suggest another solution which i found to be easy. Go to the route folder your-app-folder/routes/web.php and register a new route as follows

Route::get('/linkstorage', function () {
    Artisan::call('storage:link')
});

then go to your website www.example.com/linkstorage and it will take you to a blank page. that's it. The storage folder will be create. I hope it helps someone.

查看更多
登录 后发表回答