Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

untymage's avatar

How to save file when using Storage::readStream() ?

I want to download a large file via google driver like:

$stream = Storage::disk('google')->readStream('large-file.zip');
// how to save this to a local file ?

It return stream resource as output, So how to save this in local disk as zip file ?

0 likes
11 replies
untymage's avatar

@Sinnbeck It's my question it return stream output into $stream variable, So how do i save this as file ?

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@untymage not at a computer now but how about

$stream = Storage::disk('google')->readStream('large-file.zip');
Storage::disk('local')->writeStream('/path/large-file.zip', $stream);
1 like
untymage's avatar

@Sinnbeck Allowed memory size of 536870912 bytes exhausted (tried to allocate 4173332 80 bytes)

Sinnbeck's avatar

@untymage yeah I assume it reads it into memory. It might be better with a clean copy job. I'll check to see if there is a built in method

1 like
Sinnbeck's avatar

Try

Storage::disk('local')->put(
    'large-file.zip', 
    Storage::disk('google')->get('large-file.zip')); 
untymage's avatar

@Sinnbeck same error Allowed memory size of 536870912 bytes exhausted (tried to allocate 648091640 bytes)#0 {main}

Sinnbeck's avatar

@untymage currently my only suggestion is to try and increase max memory to 1024 mb which I would assume is the steam size

Sinnbeck's avatar

With the stream you can also try closing the stream

$stream = Storage::disk('google')->readStream('large-file.zip');
Storage::disk('local')->writeStream('/path/large-file.zip', $stream);
fclose($stream);

Please or to participate in this conversation.