示例#1
0
 /**
  * {@inheritdoc}
  */
 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");
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 function saveFile(BackupFileReadableInterface $file)
 {
     // Set some default download headers.
     $headers = array(array('key' => 'Content-Disposition', 'value' => 'attachment; filename="' . $file->getFullName() . '"'), array('key' => 'Cache-Control', 'value' => 'no-cache'));
     // Set a mime-type header.
     if ($mime = $file->getMeta('mimetype')) {
         $headers[] = array('key' => 'Content-Type', 'value' => $mime);
     } else {
         // Get the mime type for this file if possible
         $mime = 'application/octet-stream';
         $mime = $this->plugins()->call('alterMime', $mime, array('ext' => $file->getExtLast()));
         $headers[] = array('key' => 'Content-Type', 'value' => $mime);
     }
     // In some circumstances, web-servers will double compress gzipped files.
     // This may help aleviate that issue by disabling mod-deflate.
     if ($file->getMeta('mimetype') == 'application/x-gzip') {
         if (function_exists('apache_setenv')) {
             apache_setenv('no-gzip', '1');
         }
         $headers[] = array('key' => 'Content-Encoding', 'value' => 'gzip');
     }
     if ($size = $file->getMeta('filesize')) {
         $headers[] = array('key' => 'Content-Length', 'value' => $size);
     }
     // Suppress the warning you get when the buffer is empty.
     @ob_end_clean();
     if ($file->openForRead()) {
         foreach ($headers as $header) {
             // To prevent HTTP header injection, we delete new lines that are
             // not followed by a space or a tab.
             // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
             $header['value'] = preg_replace('/\\r?\\n(?!\\t| )/', '', $header['value']);
             header($header['key'] . ': ' . $header['value']);
         }
         // Transfer file in 1024 byte chunks to save memory usage.
         while ($data = $file->readBytes(1024 * 512)) {
             print $data;
         }
         $file->close();
     }
     // @TODO Throw exception.
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 function saveFile(BackupFileReadableInterface $file)
 {
     $out = array();
     // Quick and dirty way to html format this output
     if ($this->confGet('format') == 'html') {
         print '<pre>';
     }
     // Output the metadata
     if ($this->confGet('showmeta')) {
         print "---------------------\n";
         print "Metadata: \n";
         print_r($file->getMetaAll());
         print "---------------------\n";
     }
     // Output the body
     if ($this->confGet('showbody')) {
         print "---------------------\n";
         print "Body: \n";
         $max = $this->confGet('maxbody');
         $chunk = min($max, 1024);
         if ($file->openForRead()) {
             // Transfer file in 1024 byte chunks to save memory usage.
             while ($max > 0 && ($data = $file->readBytes($chunk))) {
                 print $data;
                 $max -= $chunk;
             }
             $file->close();
         }
         print "---------------------\n";
     }
     // Quick and dirty way to html format this output
     if ($this->confGet('format') == 'html') {
         print '</pre>';
     }
     exit;
 }
示例#4
0
 /**
  * This will be called when all files have been added. It gives the implementation
  * a chance to clean up and commit the changes if needed.
  *
  * @return mixed
  */
 public function closeArchive()
 {
     if ($this->archive) {
         $this->archive->close();
     }
 }
示例#5
0
 /**
  * BZip encode a file.
  *
  * @param \BackupMigrate\Core\File\BackupFileReadableInterface $from
  * @param \BackupMigrate\Core\File\BackupFileWritableInterface $to
  * @return bool
  */
 protected function _bzipEncode(BackupFileReadableInterface $from, BackupFileWritableInterface $to)
 {
     $success = FALSE;
     if (!$success && function_exists("bzopen")) {
         if (($fp_out = bzopen($to->realpath(), 'w')) && $from->openForRead()) {
             while ($data = $from->readBytes(1024 * 512)) {
                 bzwrite($fp_out, $data);
             }
             $success = TRUE;
             $from->close();
             bzclose($fp_out);
         }
     }
     return $success;
 }