Laravel 文档 ( https://laravel.com/docs/5.2/filesystem#storing-files ) 声明了这一点:
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);
我想要保存一个大于我的 php 内存限制 (512MB) 的文件,因此当我这样做时,我收到内存错误:
FatalErrorException in Local.php line 128: Allowed memory size of 536870912 bytes exhausted (tried to allocate 377028088 bytes).
如何使用文档中所示的流媒体功能?如何从文件路径转到“PHP 资源”?
最佳答案
PHP 不允许您上传该大小的文件。文档中指出的资源是这种 PHP resource
以下是使用 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));
关于php - Laravel - 将 PHP 资源传递给 Storage::put,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38595304/