Ejemplo n.º 1
0
 public function zip()
 {
     if (!CONFIG()->pool_zips) {
         throw new Rails\ActiveRecord\Exception\RecordNotFoundException();
     }
     $pool = Pool::find($this->params()->id);
     $files = $pool->get_zip_data($this->params()->all());
     $zip = new ZipStream($pool->pretty_name() . '.zip');
     foreach ($files as $file) {
         list($path, $filename) = $file;
         $zip->addLargeFile($path, $filename);
     }
     $zip->finalize();
     $this->render(['nothing' => true]);
 }
Ejemplo n.º 2
0
 /**
  * Sends all files from a set of rows of a users table to the client.
  * @param string $name name of the database table
  * @param string $rowIds ids of the rows
  */
 public function row($table, array $rowIds)
 {
     // look for the files in the table
     $rowFiles = $this->_getFilesInRow($table, $rowIds);
     if (empty($rowFiles)) {
         throw new Daiquiri_Exception_NotFound();
     }
     // leave some time for the file to be transferred
     ini_set('max_execution_time', 3600);
     // setup zipped transfer
     $fileName = $table . ".zip";
     $zip = new ZipStream($fileName);
     $comment = "All files connected to rows " . implode(", ", $rowIds) . " of table " . $table . " downloaded on " . date('l jS \\of F Y h:i:s A');
     $zip->setComment($comment);
     // look for the files in the file system and stream files
     foreach ($rowFiles as $rowFile) {
         // look for file
         $file = $this->_findFile($rowFile);
         if (empty($file)) {
             continue;
         }
         // zip and stream
         $fhandle = fopen($file, "rb");
         $zip->addLargeFile($fhandle, $rowFile);
         fclose($fhandle);
     }
     $zip->finalize();
 }
Ejemplo n.º 3
0
<?php

// Example. Zip all .html files in the current directory and save to current directory.
// Make a copy, also to the current dir, for good measure.
//$mem = ini_get('memory_limit');
//$extime = ini_get('max_execution_time');
//
////ini_set('memory_limit', '512M');
//ini_set('max_execution_time', 120);
include_once "ZipStream.php";
//print_r(ini_get_all());
$fileTime = date("D, d M Y H:i:s T");
$chapter1 = "Chapter 1\n" . "Lorem ipsum\n" . "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n";
$zip = new ZipStream("ZipStreamExample1s.zip");
$zip->setComment("Example Zip file for Large file sets.\nCreated on " . date('l jS \\of F Y h:i:s A'));
$zip->openStream("big one3.txt");
$zip->addStreamData($chapter1 . "\n\n\n");
$zip->addStreamData($chapter1 . "\n\n\n");
$zip->addStreamData($chapter1 . "\n\n\n");
$zip->closeStream();
$zip->addDirectory("Empty Dir");
$zip->finalize();
// Mandatory, needed to send the Zip files central directory structure.
Ejemplo n.º 4
0
<?php

/*
 * A test to see if it was possible to recreate the result of
 *  Issue #7, if not the cause.
 * And a demnostration why the author of the script calling zip
 *  needs to be dilligent not to add extra characters to the output.
 */
include_once "ZipStream.php";
$zip = new ZipStream("test.zip");
/*
 * As seen in the output, the above construct with a PHP end and start tag after
 * creating the ZipStream is a bad idea. The Zip file will be starting with a
 * space followed by the newline characters.
 */
$zip->addDirectory("test");
$zip->addDirectoryContent("testData/test", "test");
return $zip->finalize();