首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >League/Flysystem fstat()期望参数1是资源,对象给定

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

Stack Overflow用户
提问于 2015-06-09 17:06:21
回答 3查看 6.1K关注 0票数 8

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

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

代码语言:javascript
复制
// 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",

有什么原因吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-06-09 17:35:51

在您的$image对象上的某个类型转换用它做字符串之前,您可能是幸运的,我想简单地将最后一行更改为

代码语言:javascript
复制
$disk->put("img/album/$id/$filename", $image->__toString());

将修复这个问题,而且安全一些,因为put方法只接受字符串(并将php资源的实现视为wekk)。

从长远来看,这将使您与更改保持兼容。

票数 11
EN

Stack Overflow用户

发布于 2015-06-13 16:12:35

更好的方法是键入强制转换编码的输出:

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

代码语言:javascript
复制
$image->encode('jpg');
$disk->put("img/album/$id/$filename", (string) $image);
票数 17
EN

Stack Overflow用户

发布于 2018-12-05 06:41:56

我有"intervention/image": "^2.4",

__toString()不适合我,文件被破坏了.我做了->stream()->getContents()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30738520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档