12

laravel 5.3,如果我从表单上传文件,它将存储在自己的存储目录中。然后我应该在公共路径中创建一个symlink到该存储路径的路径。

由于限制,我不能在我的系统上创建符号链接。如何将文件直接上传到public/uploads而不是storage/app/uploads

我试图设置路径,AppServiceProvider.php但它不起作用。

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';
    // });

}

“不工作”是指它仍在上传到默认存储目录。我还清除了缓存。

这是上传部分(在控制器中使用):

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

感谢您的任何提示。:)

4

1 回答 1

27

在 Laravel 5 中,你现在必须在config/filesystems.php. 您可以像这样添加新磁盘:

'disks' => [

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

]

然后执行以下操作来使用它:

Storage::disk('uploads')->put('filename', $file_content);
于 2016-08-25T20:55:49.567 回答