You are here

function StreamDestination::saveFile in Backup and Migrate 8.4

Save a file to the destination.

Parameters

\BackupMigrate\Core\File\BackupFileReadableInterface $file: The file to save.

Overrides WritableDestinationInterface::saveFile

2 methods override StreamDestination::saveFile()
BrowserDownloadDestination::saveFile in lib/backup_migrate_core/src/Destination/BrowserDownloadDestination.php
Save a file to the destination.
DebugDestination::saveFile in lib/backup_migrate_core/src/Destination/DebugDestination.php
Save a file to the destination.

File

lib/backup_migrate_core/src/Destination/StreamDestination.php, line 21

Class

StreamDestination
Class StreamDestination.

Namespace

BackupMigrate\Core\Destination

Code

function saveFile(BackupFileReadableInterface $file) {
  $stream_uri = $this
    ->confGet('streamuri');
  if ($fp_out = fopen($stream_uri, 'w')) {
    $file
      ->openForRead();
    while ($data = $file
      ->readBytes(1024 * 512)) {
      fwrite($fp_out, $data);
    }
    fclose($fp_out);
    $file
      ->close();
  }
  else {
    throw new \Exception("Cannot open the file {$stream_uri} for writing");
  }
}