laravel League/Flysystem fstat() 期望参数 1 是资源,给定的对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30738520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
League/Flysystem fstat() expects parameter 1 to be resource, object given
提问by NightMICU
I am in the process of upgrading a project from Laravel 5 to 5.1. One package that needed to be updated was League\Flysystem
.
我正在将项目从 Laravel 5 升级到 5.1。需要更新的一个包是League\Flysystem
.
I am using Intervention\Image
to resize an image and then Flysystem to save it to S3. The code below was working with 5.0 -
我正在使用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);
But now I am receiving the following error:
fstat() expects parameter 1 to be resource, object given
, thrown in league\flysystem\src\Util.php
, line 250.
但是现在我收到以下错误:
fstat() expects parameter 1 to be resource, object given
,抛出league\flysystem\src\Util.php
,第 250 行。
I am using "intervention/image": "~2.1"
, "league/flysystem-aws-s3-v3" : "~1.0",
我正在使用"intervention/image": "~2.1"
,"league/flysystem-aws-s3-v3" : "~1.0",
Any ideas what might be causing this?
任何想法可能导致这种情况?
回答by Citizen
The better way to do this is to type cast the encoded output:
更好的方法是对编码输出进行类型转换:
http://image.intervention.io/api/encode
http://image.intervention.io/api/encode
$image->encode('jpg');
$disk->put("img/album/$id/$filename", (string) $image);
回答by ChristianM
You might have been lucky before some type casting on your $image
object made a string out of it, I guess a simple change of your last line to
在您的$image
对象上进行某种类型转换之前,您可能很幸运,我想将您的最后一行简单更改为
$disk->put("img/album/$id/$filename", $image->__toString());
will fix the problem and is safer anyway as the put
method officially only accepts strings (and looking at the implementation of php resources as wekk).
That should keep you compatible to changes in the long run.
将解决问题并且无论如何都更安全,因为该put
方法正式只接受字符串(并查看 php 资源的实现作为 wekk)。
从长远来看,这应该能让你适应变化。
回答by Tomer Ofer
i got version "intervention/image": "^2.4",
我有版本 "intervention/image": "^2.4",
The __toString()
didn't work for me, the file was created corrupted...
i did ->stream()->getContents()
.
在__toString()
没有工作对我来说,创建该文件损坏......我->stream()->getContents()
。