How to change storage path in laravel 5.3 to public?

女生的网名这么多〃 提交于 2019-11-29 12:35:29

问题


In laravel 5.3, if I upload a file from a form, it will be stored in own storage directory. Then I should create a symlink to that storage path in public path.

I can't use creating symlinks on my system because of the limitation. How can I upload files directly to public/uploads instead of storage/app/uploads?

I tried to set the path in AppServiceProvider.php but it doesn't work.

public function register()
{
    //not working:
    $this->app->useStoragePath( $this->app->basePath() .  "/upload");

    //also not working:
    // $this->app->bind('path.storage', function () {
    // return $this->app->basePath() . '/upload';
    // });

}

by "not working" I mean that it is still uploading into the default storage directory. I cleared also the cache.

Here is the upload part (used in a controller):

        $request->image->storeAs("uploads", "uploaded_image.jpg");

Thanks for any hints. :)


回答1:


In Laravel 5 you now have to do this in config/filesystems.php. You can add a new disk like so:

'disks' => [

    'uploads' => [
          'driver' => 'local',
          'root'   => public_path(), // previously storage_path();
    ],

]

and then do the following to use it:

Storage::disk('uploads')->put('filename', $file_content);


来源:https://stackoverflow.com/questions/39154484/how-to-change-storage-path-in-laravel-5-3-to-public

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!