0

Using php-opencloud, I manage to connect to trigger the download of my images. Large files (20, 30, or 50 GB).

Following the doc, with

$image = $service->getImage($image_id);
$stream = $image->downloadData();

I can see that Psr7 is downloading request body in a temp file /tmp/php... but I simply can't figure how to redirect the data to store them in a persistent local file.

Using fopen, fwrite I had problem of memory exhaustion and a

$fp = fopen( $local_file, 'w' );
stream_copy_to_stream( $image->downloadData(), $fp );

triggers no error but $local_file is still at 0 bytes at the end.

How can I achieve this ?

ZalemCitizen
  • 474
  • 7
  • 13

1 Answers1

1

I tried during hours and I knew it was dumb as hell :

while( !$stream->eof() ) {
  $buffer = $stream->read( 4096 );
  fwrite( $fp, $buffer );
}

fclose( $fp );

is working nicely

ZalemCitizen
  • 474
  • 7
  • 13