You are here

public function TarArchiveWriter::addFile in Backup and Migrate 5.0.x

Parameters

string $real_path: The real path to the file. Can be a stream URI.

string $new_path: The path that the file should have in the archive. Leave blank to use the original path.

Overrides ArchiveWriterInterface::addFile

File

src/Core/Service/TarArchiveWriter.php, line 41

Class

TarArchiveWriter
@package Drupal\backup_migrate\Core\Service

Namespace

Drupal\backup_migrate\Core\Service

Code

public function addFile($real_path, $new_path = '') {
  $this->archive
    ->openForWrite(TRUE);
  $new_path = $new_path ? $new_path : $real_path;
  $this
    ->writeHeader($real_path, $new_path);
  $fp = @fopen($real_path, "rb");
  while (($v_buffer = fread($fp, 512)) != '') {
    $v_binary_data = pack("a512", "{$v_buffer}");
    $this->archive
      ->write($v_binary_data);
  }
  fclose($fp);
}