2016-07-26 21 views
3

Laravelのドキュメント(https://laravel.com/docs/5.2/filesystem#storing-files)状態この置く:そう際、Laravelはストレージ::にPHPのリソースを渡すと

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のメモリ制限(512メガバイト)を超えるファイルを保存するために探していますが、私これを行うと、メモリエラーが発生する:

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

ドキュメントに示されているようにストリーミング機能を使用するにはどうすればよいですか?ファイルパスから "PHPリソース"に移動するにはどうすればよいですか?

答えて

2

PHPは、あなたがそのサイズのファイルをアップロードすることを許可していません。ドキュメントで指摘されているリソースは、この種類のものですPHP resource

ここでは、外部イメージURLからInterventionを使用してイメージを作成する簡単な例を示します。 Interventionライブラリは、PHPリソースリストの下にあるGDライブラリを使用します。

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

ここでは、ファイルをアップロードする際のコード例を示します。

+0

ファイルストリームから私を救う – Michael

関連する問題