【问题标题】:League/Flysystem fstat() expects parameter 1 to be resource, object givenLeague/Flysystem fstat() 期望参数 1 是资源,给定对象
【发布时间】:2015-08-24 15:41:00
【问题描述】:

我正在将项目从 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);

但现在我收到以下错误: 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",

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

【问题讨论】:

    标签: php laravel laravel-5 intervention flysystem


    【解决方案1】:

    更好的方法是对编码的输出进行类型转换:

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

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

    【讨论】:

    • 我实际上同意,按照建议进行类型转换:)
    • 这种方法适用于 Guzzle。漂亮而简单。
    【解决方案2】:

    在您的 $image 对象上的某些类型转换生成一个字符串之前,您可能已经很幸运了,我想您最后一行的简单更改为

    $disk->put("img/album/$id/$filename", $image->__toString());
    

    将解决问题并且更安全,因为put 方法正式只接受字符串(并将 php 资源的实现视为 wekk)。
    从长远来看,这应该让您适应变化。

    【讨论】:

    • 现在接收命令(_toString) is not available for driver (Gd)
    • 这是书写错误 (_toString) 还是只有一个下划线?它应该是带有两个下划线的 __toString()。
    • 当然,首先put 接受字符串或php 资源。我猜它之前的工作是因为在 flysystem 代码中的某个地方,输入参数上发生了一个字符串函数或一个显式字符串转换(所以 (string) $image 的行中的某些内容与 $image->__toString() )。这是一种神奇的方法,用于在必要时将给定对象转换为字符串,并干预 Image 实现它。 _toString 未实现并引发错误,因为干预尝试将其作为图像(操作)命令执行。
    • 知道了,谢谢!预计这将更难解决。非常感谢您的帮助。 :)
    • 太好了,我能帮上忙。 :) 有时,如果您认为某些事情很难解决,那么您看不到简单的解决方案,有时也会遇到同样的问题 :)
    【解决方案3】:

    我得到了版本"intervention/image": "^2.4",

    __toString() 对我不起作用,文件创建时已损坏... 我做了->stream()->getContents()

    【讨论】:

      猜你喜欢
      • 2011-09-23
      • 1970-01-01
      • 2011-06-05
      • 2011-03-26
      • 2012-01-21
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 2014-02-08
      相关资源
      最近更新 更多