You are here

public function StreamDestination::saveFile in Backup and Migrate 5.0.x

Save a file to the destination.

Parameters

\Drupal\backup_migrate\Core\File\BackupFileReadableInterface $file: The file to save.

Overrides WritableDestinationInterface::saveFile

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

File

src/Core/Destination/StreamDestination.php, line 21

Class

StreamDestination
@package Drupal\backup_migrate\Core\Destination

Namespace

Drupal\backup_migrate\Core\Destination

Code

public 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");
  }
}