FilesystemAdapter无法转换为字符串Laravel

时间:2016-05-26 13:35:37

标签: php laravel laravel-5.2

我有一张照片上传表单,转到此代码

$this->validate($request, [
            'image' => 'required|image|max:3000|mimes:jpeg,jpg,png',
        ]);
        $user = Auth::user();

        $usersname = $user->username;
       $file = $request->file('image');
      $ext = $file->getClientOriginalExtension();
      $path = Storage::disk('uploads');

        $filename = $usersname . '.' . $ext;

        if (Storage::disk('uploads')->has($filename)) {
            Storage::delete($filename);
        }
       Storage::disk('uploads')->put($filename, File::get($file));

       $resizedImg = Image::make($path . DIRECTORY_SEPARATOR . $filename)->resize(200,200)->save($path . DIRECTORY_SEPARATOR . $filename);

        return redirect()->route('profile.index', 
                ['username' => Auth::user()->username]);
    }

当我执行此代码时,它会给我这个错误

ErrorException in ProfileController.php line 71:
Object of class Illuminate\Filesystem\FilesystemAdapter could not be converted to string

第71行是以$ resizedImg开头的行,但照片会保存到正确的目录中,但未调整大小。

我在filesystems.php文件中定义了上传内容,如下所示

 'disks' => [

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

1 个答案:

答案 0 :(得分:1)

$path内容驱动程序,但你试图将它用作字符串,这就是问题所在。尝试使用类似的东西:

$path = '/uploads';