League/Flysystem fstat()期望参数1是资源,给定对象

Nig*_*ICU 8 php laravel laravel-5 flysystem intervention

我正在将项目从Laravel 5升级到5.1.需要更新的一个包是League\Flysystem.

Intervention\Image用来调整图像大小,然后使用Flysystem将其保存到S3.下面的代码与5.0一起使用 -

// Album ID
$id = $request->input('id');
// Filename for this photo
$filename = str_random() . ".jpg";

// Get the storage disk
$disk = Storage::disk('s3');

// Resize the photo
$image = Image::make($request->file('photo'));
$image->orientate();
$image->resize(1024, 748, function ($constraint) {
            $constraint->aspectRatio();
});
$image->encode('jpg');
// Save the photo to the disk
$disk->put("img/album/$id/$filename", $image);
Run Code Online (Sandbox Code Playgroud)

但现在我收到以下错误: fstat() expects parameter 1 to be resource, object given,引入league\flysystem\src\Util.php第250行.

我在用"intervention/image": "~2.1","league/flysystem-aws-s3-v3" : "~1.0",

可能导致这种情况的任何想法?

Cit*_*zen 16

更好的方法是输入编码输出:

http://image.intervention.io/api/encode

$image->encode('jpg');
$disk->put("img/album/$id/$filename", (string) $image);
Run Code Online (Sandbox Code Playgroud)

  • 我实际上同意,做类似建议的类型:) (3认同)
  • 这种方法适用于Guzzle.很好,很简单. (2认同)

Chr*_*anM 11

你可能很幸运,在你的$image对象上的一些类型转换之前,它就是一个字符串,我想你最后一行的简单改变

$disk->put("img/album/$id/$filename", $image->__toString());
Run Code Online (Sandbox Code Playgroud)

将修复问题,并且无论如何更安全,因为该put方法正式只接受字符串(并将php资源的实现视为wekk).
从长远来看,这应该让你兼容变化.