4

The Laravel docs (https://laravel.com/docs/5.2/filesystem#storing-files) state this:

Storing Files

The put method may be used to store a file on disk. You may also pass a PHP resource to the put method, which will use Flysystem's underlying stream support. Using streams is greatly recommended when dealing with large files:

Storage::put('file.jpg', $contents);

Storage::put('file.jpg', $resource);

I am looking to save a file larger than my php memory limit (512MB), so when I do this, I get a memory error:

FatalErrorException in Local.php line 128: Allowed memory size of 536870912 bytes exhausted (tried to allocate 377028088 bytes).

How do I use the streaming functionality as indicated in the docs? How do I go from a file path to a "PHP resource"?

4

1 回答 1

3

PHP 不允许您上传具有该大小的文件。文档中指出的资源是这种PHP 资源

这是一个使用Intervention从外部图像 URL 创建图像的简单示例。Intervention 库使用 GD 库,它位于 PHP 资源列表下。

$image = Image::make('Your Extenal URL')->stream();
Storage::put('image_name.jpg', $image->getContents());   

在您的情况下,这是上传文件的示例代码。

$file = Request::file('file_field');
Storage::put($file->getClientOriginalName(), File::get($file));
于 2016-07-28T10:43:23.240 回答