Example #1
1
function create_zip_package($dir, $destination)
{
    $zip = new ZipArchive();
    if ($zip->open($destination, ZipArchive::OVERWRITE) !== true) {
        echo 'Failed to create ' . $destination . ' with code ' . $ret;
        return false;
    } else {
        $zip->addGlob($dir . '/*.php', GLOB_BRACE, array('add_path' => '/' . basename($dir) . '/', 'remove_all_path' => true));
        $zip->addFile($dir . '/package-info.xml', 'package-info.xml');
        $zip->addFile($dir . '/agreement.txt', 'agreement.' . basename($dir) . '.txt');
        $zip->close();
        return true;
    }
}
 /**
  * Скачать архив с резервной копией
  *
  */
 public function downloadAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     if ($this->hasParam('dir')) {
         $dir = $this->getParam('dir');
         $zip = new ZipArchive();
         $ret = $zip->open($zipFile = TEMP_PATH . DS . $dir . '.zip', ZipArchive::OVERWRITE);
         if ($ret !== TRUE) {
             printf('Failed with code %d', $ret);
         } else {
             $options = array('add_path' => 'backup/', 'remove_all_path' => TRUE);
             $zip->addGlob(TEMP_PATH . DS . 'Backups/' . $dir . '/*.*', GLOB_BRACE, $options);
             $zip->close();
             header('Content-Type: ' . System_Mime_Type::mime($zipFile));
             header('Content-Length: ' . filesize($zipFile));
             header("Content-Disposition: attachment; filename=\"" . basename($zipFile) . "\";");
             header("Content-Transfer-Encoding: binary");
             ob_end_flush();
             readfile($zipFile);
             unlink($zipFile);
             exit;
         }
     }
 }
Example #3
0
 public static function makeComicBookFromDir($dir, $extension = "cbr")
 {
     if (!is_dir($dir)) {
         return false;
     }
     $zipFile = $dir . "." . $extension;
     $zipArchive = new ZipArchive();
     if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE)) {
         die("Failed to create archive\n");
     }
     $zipArchive->addGlob($dir . "/*");
     if (!$zipArchive->status == ZIPARCHIVE::ER_OK) {
         echo "Failed to write files to zip\n";
     }
     $zipArchive->close();
     return true;
 }
Example #4
0
<?php

require "vendor/autoload.php";
\D2LView\StaticPages::generate(".", "phtml");
$zip = new \ZipArchive();
$ret = $zip->open('courseShell.zip', ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
if ($ret !== TRUE) {
    printf('Failed with code %d', $ret);
} else {
    $zip->addGlob('*.{html,xml}', GLOB_BRACE);
    $zip->close();
}
 private function generarZip()
 {
     $zip = new ZipArchive();
     $ret = $zip->open($this->pathCirculares . "/circulares{$_SESSION['usuarioPortal']['Id']}.zip", ZipArchive::OVERWRITE);
     if ($ret !== TRUE) {
         printf('Erróneo con el código %d', $ret);
     } else {
         $options = array('add_path' => "/", 'remove_all_path' => TRUE);
         $ok = $zip->addGlob("{$this->pathCirculares}/{$_SESSION['usuarioPortal']['Id']}_*.rtf", GLOB_BRACE, $options);
         $zip->close();
         if ($ok) {
             // Borrar los archivos
             foreach (glob("{$this->pathCirculares}/{$_SESSION['usuarioPortal']['Id']}_*.rtf") as $nombreArchivo) {
                 @unlink($nombreArchivo);
             }
         }
     }
 }
Example #6
0
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
error_reporting(E_ERROR);
require '../init.php';
$data['error'] = "error";
$data['message'] = "Unknown error";
try {
    if (!$authAdmin) {
        throw new Exception("Access denied. Please login as an Admin to continue.");
    }
    $dump = new DumpSQL();
    $sqlFile = $dump->getDumpFile();
    $zipFile = "data/backup_" . BASE . "_" . date('Y-m-d') . ".zip";
    $options = array('remove_all_path' => true, 'add_path' => 'screens/');
    $zip = new ZipArchive();
    $zip->open(INSTALL_PATH . $zipFile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
    $zip->addFile(INSTALL_PATH . $sqlFile, basename($sqlFile));
    $zip->addGlob(DATA_PATH . '*', null, $options);
    $zip->close();
    unlink(INSTALL_PATH . $sqlFile);
    $data['error'] = 'OK';
    $data['message'] = $LANG['Backup_OK'];
    $data['dumpfile'] = $zipFile;
} catch (Exception $e) {
    $data['message'] = $e->getMessage();
}
header('HTTP/1.1 200 OK');
header('Content-type: application/json; charset=UTF-8');
echo ")]}',\n";
// Pour sécu anti injection JSONP
echo json_encode($data, JSON_UNESCAPED_UNICODE);
Example #7
0
} elseif ($action === 'download_attachments') {
    try {
        // Get the year
        $year = date('Y', strtotime($listPeriode[$id_periode - 1]['date_debut']));
        // Create the zip
        $zipFilename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'afup_justificatifs-' . $year . '.zip';
        $zip = new ZipArchive();
        $ret = $zip->open($zipFilename, ZipArchive::CREATE);
        if ($ret !== true) {
            throw new RuntimeException("Impossible to open the Zip archive.");
        } else {
            for ($month = 1; $month <= 12; $month++) {
                $searchDir = sprintf('%d%02d', $year, $month);
                $zipDir = sprintf('%d%02d', $year, $month);
                $options = ['add_path' => 'afup_justificatifs-' . $year . '/' . $zipDir . '/', 'remove_all_path' => true];
                $zip->addGlob(AFUP_CHEMIN_RACINE . '/uploads/' . $searchDir . '/*.*', 0, $options);
            }
            $zip->close();
            // Download it
            header('Content-Type: application/zip');
            header("Content-Transfer-Encoding: Binary");
            header("Content-disposition: attachment; filename=\"" . basename($zipFilename) . "\"");
            readfile($zipFilename);
            unlink($zipFilename);
            exit;
        }
    } catch (Exception $e) {
        header('HTTP/1.1 400 Bad Request');
        header('X-Info: ' . $e->getMessage());
        exit;
    }
Example #8
0
 private function createModArchive()
 {
     $zip = new ZipArchive();
     $filename = self::PACKAGE . '-' . self::VERSION . '.zip';
     if ($zip->open($this->getBuildDir() . DIRECTORY_SEPARATOR . $filename, ZipArchive::CREATE) !== true) {
         throw new RuntimeException('Zip create error');
     }
     $zip->addGlob('*.php');
     $zip->addGlob('*.xml');
     $zip->addGlob('*.txt');
     $zip->addGlob('languages/*.xml');
     $zip->addGlob('upgrades/*.*');
     $zip->deleteName('RoboFile.php');
     //self
     $zip->close();
     $this->say("Created zip {$filename}");
 }
Example #9
0
 function generateAttachmentDownload()
 {
     $file_path = getcwd() . '/output_files_work/';
     array_map('unlink', glob($file_path . "*"));
     $zipFileName = getcwd() . '/output_files/hy_image_2016.zip';
     //cleanup
     array_map('unlink', glob($file_path . "*"));
     array_map('unlink', glob(getcwd() . '/output_files/*'));
     $tables = ["articles", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9"];
     $this->setReportFilter();
     for ($i = 0; $i < count($tables); $i++) {
         array_map('unlink', glob($file_path . "*"));
         //extract attachment out from DB
         $query = "select attachment_type, attachment, attachment_name from " . $tables[$i] . " where attachment is not null";
         if (trim($this->report_filter) != '') {
             $query = $query . " AND " . $this->report_filter;
         }
         $result = $this->runQuery($query);
         foreach ($result as $row) {
             file_put_contents($file_path . $row['attachment_name'], $row['attachment']);
         }
         //create zip file
         $zip = new ZipArchive();
         if ($zip->open($zipFileName, ZipArchive::CREATE) !== TRUE) {
             exit("cannot open <{$zipFileName}>\n");
         }
         $options = array('add_path' => $i + 1 . '/', 'remove_all_path' => TRUE);
         $zip->addGlob($file_path . "/*", GLOB_BRACE, $options);
         $zip->close();
     }
     if (file_exists($zipFileName)) {
         //send zip file to browser
         $download_file_name = "hy_" . $_POST['wuzhong'] . ".zip";
         header("Content-Type: application/zip");
         header("Content-Disposition: attachment; filename={$download_file_name}");
         header("Content-Length: " . filesize($zipFileName));
         readfile($zipFileName);
     } else {
         $this->f3->set('message', "没有找到附加文件");
         $this->f3->set('report_filter', $_POST['wuzhong']);
         $this->f3->set('view', 'report/report.html');
         $this->f3->set('showMenu', false);
         echo Template::instance()->render('layout.htm');
         //		echo Template::instance()->render('report.html');
         echo $this->generatePageBody();
     }
 }
Example #10
0
function zipFolderContent($folder, $fileName)
{
    $zip = new ZipArchive();
    $zipFile = $folder . '/' . $fileName . '.zip';
    if ($zip->open($zipFile, ZipArchive::CREATE) !== TRUE) {
        die('cannot open ' . $fileName);
    }
    $options = array('add_path' => $fileName . '/', 'remove_all_path' => TRUE);
    $zip->addGlob($folder . '/*', 0, $options);
    $zip->close();
}
Example #11
0
<?php

$zipFile = new ZipArchive();
$zipFile->open("./binaries.zip", ZipArchive::CREATE);
$directories = ["../imagick/images/spiderGif/*.png"];
foreach ($directories as $directory) {
    $zipFile->addGlob($directory);
}
$zipFile->close();
Example #12
0
$rows = $db->query("SELECT * FROM backup where type like '27' and userid = " . $userid);
while ($row = $rows->fetchArray()) {
    $source = $row['image'];
    $refid = $row['refid'];
    //$source = "https://myapps.gia.edu/ReportCheckPortal/downloadReport.do?reportNo=1152872617&weight=1.35";
    $ch = curl_init($source);
    $destination = "./saved/" . $username . "." . $refid . ".jpg";
    $file = fopen($destination, "w+");
    curl_setopt($ch, CURLOPT_FILE, $file);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($Channel, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    //curl_setopt($ch, CURLOPT_SSLVERSION,3);
    $data = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);
    fclose($File);
    print $refid . "<br>";
}
$zipFile = "./" . $userid . ".zip";
$zipArchive = new ZipArchive();
if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE)) {
    die("Failed to create archive\n");
}
$zipArchive->addGlob("./saved/" . $userid . "*.jpg");
if (!$zipArchive->status == ZIPARCHIVE::ER_OK) {
    echo "Failed to write files to zip\n";
}
$zipArchive->close();
 /**
  * Baut die ZIP-Datei auf.
  */
 private function buildZipFile()
 {
     $this->changePermissions();
     shell_exec('cd "' . $this->sProjectPath . '" && sudo make singlehtml');
     $zip = new ZipArchive();
     if ($zip->open('' . $this->sProjectPath . '/html.zip', ZipArchive::OVERWRITE)) {
         $zip->addFile('' . $this->sProjectPath . '/build/singlehtml/index.html', "index.html");
         $zip->addFile('' . $this->sProjectPath . '/build/singlehtml/objects.inv', "objects.inv");
         $zip->addGlob('' . $this->sProjectPath . '/build/singlehtml/_static/*', GLOB_ERR, array('add_path' => '_static/', 'remove_all_path' => TRUE));
         $zip->close();
     } else {
         die("zip erstellung ");
     }
 }
Example #14
0
 /**
  * Add files
  *
  * @param    string       $subfolder  The subfolder
  * @param    \ZipArchive  $zip        The zip object
  * @param    string       $path       Optional path
  *
  * @return  void
  */
 private function addFiles($subfolder, $zip, $path = null)
 {
     if (!$path) {
         $path = $this->current;
     }
     if ($subfolder->isFile()) {
         // Set all separators to forward slashes for comparison
         $usefolder = str_replace('\\', '/', $subfolder->getPath());
         // Drop the folder part as we don't want them added to archive
         $addpath = str_ireplace($path, '', $usefolder);
         // Remove preceding slash
         $findfirst = strpos($addpath, '/');
         if ($findfirst == 0 && $findfirst !== false) {
             $addpath = substr($addpath, 1);
         }
         if (strlen($addpath) > 0 || empty($addpath)) {
             $addpath .= '/';
         }
         $options = array('add_path' => $addpath, 'remove_all_path' => true);
         $zip->addGlob($usefolder . '/*.*', GLOB_BRACE, $options);
     }
 }
<?php

$dirname = dirname(__FILE__) . '/';
include $dirname . 'utils.inc';
$file = $dirname . '__tmp_oo_addglob.zip';
copy($dirname . 'test.zip', $file);
touch($dirname . 'foo.txt');
touch($dirname . 'bar.baz');
$zip = new ZipArchive();
if (!$zip->open($file)) {
    exit('failed');
}
$options = array('add_path' => 'baz/', 'remove_all_path' => TRUE);
if (!$zip->addGlob($dirname . '*.{txt,baz}', GLOB_BRACE, $options)) {
    echo "failed1\n";
}
if ($zip->status == ZIPARCHIVE::ER_OK) {
    dump_entries_name($zip);
    $zip->close();
} else {
    echo "failed2\n";
}
Example #16
0
 /**
  * Export a quiz to a zip file (json + pictures)
  * @return [type] [description]
  */
 public function export()
 {
     $export = array('appreciations' => array(), 'settings' => array(), 'content' => array(), 'players' => array());
     // Content export
     foreach ($this->questions as $question) {
         $contentExport = $question->export();
         $export['content'][] = $contentExport;
     }
     // Settings export
     $export['settings'] = $this->exportSettings();
     // Meta export
     $export['extraOptions'] = $this->exportExtraOptions();
     // Players export
     $export['players'] = $this->exportPlayers();
     // Upload config
     $currentTime = time();
     $upload_dir = wp_upload_dir();
     $upload_path = $upload_dir['path'];
     $file_slug = 'wpvq-' . substr(slugify($this->getName(), true), 0, 10) . '-' . $currentTime;
     // Create local upload dir
     $upload_local_path = $upload_path . '/' . $file_slug;
     if (!mkdir($upload_local_path, 0777, true)) {
         die('Error : can\'t upload.');
     }
     // Create json+pictures
     $final_json_path = $upload_local_path . '/export.json';
     // Fetch pictures ID then save them into the pictures folder
     $picturesIds = array_filter(array_value_recursive('pictureId', $export['content']));
     foreach ($picturesIds as $pictureId) {
         $url = wp_get_attachment_url($pictureId);
         $ext = pathinfo($url, PATHINFO_EXTENSION);
         if (file_put_contents("{$upload_local_path}/{$pictureId}.{$ext}", file_get_contents($url)) === FALSE) {
             die('Error : can\'t upload.');
         }
     }
     // Export appreciations with pictures
     $export['appreciations'] = $this->exportAppreciations($upload_local_path);
     $exportJson = json_encode($export);
     if (file_put_contents($final_json_path, $exportJson) === FALSE) {
         die('Error : can\'t upload.');
     }
     // Create zip file
     $final_zip_path = $upload_path . '/' . $file_slug . '.zip';
     $zip = new ZipArchive();
     if ($zip->open($final_zip_path, ZipArchive::CREATE) !== TRUE) {
         die('Error : can\'t upload.');
     }
     $zip->addGlob($upload_local_path . "/*.*", 0, array('remove_all_path' => true, 'add_path' => $file_slug . '/'));
     if (!$zip->status == ZIPARCHIVE::ER_OK) {
         die('Error : can\'t upload.');
     }
     $zip->close();
     return $final_zip_path;
 }
Example #17
0
 function createZipFromDirYii($dir, $zip_file)
 {
     $zipFile = "export.zip";
     if (file_exists($zipFile)) {
         unlink($zipFile);
     }
     $zipArchive = new ZipArchive();
     if (!$zipArchive->open($zipFile, ZIPARCHIVE::OVERWRITE)) {
         die("Failed to create archive\n");
     }
     $scanned_directory = array_diff(scandir($dir), array('..', '.'));
     $temp = $scanned_directory;
     foreach ($scanned_directory as $key => $value) {
         if (strpos($value, ".") != false) {
             unset($temp[$key]);
         }
     }
     $scanned_directory = $temp;
     /// Buat diluar MVCnya
     $zipArchive->addGlob($dir . "/*.*");
     //// buat MVCnya
     foreach ($scanned_directory as $key => $value) {
         # code...
         $zipArchive->addGlob($dir . "/" . $value . "/*.*");
     }
     /// buat didalam viewnya
     $scanned_directory = array_diff(scandir($dir . "/views/"), array('..', '.'));
     $temp = $scanned_directory;
     foreach ($scanned_directory as $key => $value) {
         if (strpos($value, ".") != false) {
             unset($temp[$key]);
         }
     }
     $scanned_directory = $temp;
     foreach ($scanned_directory as $key => $value) {
         # code...
         $zipArchive->addGlob($dir . "/views/" . $value . "/*.*");
     }
     /////////// End Buat Viewnya
     if (!$zipArchive->status == ZIPARCHIVE::ER_OK) {
         echo "Failed to write files to zip\n";
     }
     $zipArchive->close();
 }
Example #18
0
<?php

$z = new ZipArchive();
$z->open('a.zip', ZIPARCHIVE::CREATE);
/* or 'remove_all_path' => 0*/
$options = array('remove_path' => '/home/francis/myimages', 'add_path' => 'images/');
$found = $z->addGlob("/home/pierre/cvs/gd/libgd/tests/*.png", 0, $options);
var_dump($found);
$z->close();
Example #19
0
 /**
  * Build a Motif
  *
  * @param string $path
  * @param array $manifest
  */
 protected function buildMotif(string $path, array $manifest = [])
 {
     // Step One -- Let's build our .zip file
     $zipName = $manifest['supplier'] . '.' . $manifest['name'] . '.zip';
     if (\file_exists($path . '/dist/' . $zipName)) {
         \unlink($path . '/dist/' . $zipName);
         \clearstatcache();
     }
     if (\file_exists($path . '/dist/' . $zipName . '.ed25519.sig')) {
         \unlink($path . '/dist/' . $zipName . '.ed25519.sig');
         \clearstatcache();
     }
     $zip = new \ZipArchive();
     $flags = \ZipArchive::CREATE | \ZipArchive::OVERWRITE;
     // Open the zip for writing
     if ($zip->open($path . '/dist/' . $zipName, $flags) !== true) {
         echo 'Could not open .zip', "\n";
         exit(255);
         // Return an error flag
     }
     $zipOpts = ['remove_all_path' => true];
     $currentDir = \getcwd();
     \chdir($path . '/src/');
     $zip->addGlob('*.json', 0, $zipOpts);
     $zip->addGlob('*/*', 0, $zipOpts);
     \chdir($currentDir);
     $zip->setArchiveComment(\json_encode($manifest));
     if (!$zip->close()) {
         echo 'Zip archive unsuccessful', "\n";
         exit(255);
     }
     echo 'Motif built.', "\n", $path . '/dist/' . $zipName, "\n", 'Don\'t forget to sign it!', "\n";
     exit(0);
     // Return a success flag
 }
Example #20
0
 /**
  * Creates the backup with given name and description
  *
  * @param string $name filename
  * @param string $description
  * @return bool true on success, false on error
  */
 private function createBackup($name, $description = '')
 {
     $zip = new ZipArchive();
     // create empty array
     if ($zip->open(__DIR__ . '/data/' . $name, ZipArchive::CREATE) !== true) {
         return false;
     }
     // add all files
     if (!isset($this->CONFIG['backup_list']) || !is_array($this->CONFIG['backup_list'])) {
         return false;
     }
     foreach ($this->CONFIG['backup_list'] as $item) {
         $zip->addGlob($item);
     }
     // rename files as zip thinks there are CP866 filenames but they are in 1251
     // so all cyrillic names are unreadable
     for ($i = 0; $i < $zip->numFiles; $i++) {
         if ($zip->getNameIndex($i) > '') {
             $zip->renameIndex($i, iconv(filesystem_encoding(), 'CP866', $zip->getNameIndex($i)));
         }
     }
     // ok, finished
     $zip->setArchiveComment($description);
     $zip->close();
     return true;
 }
Example #21
0
    if (!copy($file, $newfile)) {
        echo "не удалось скопировать {$file}...\n";
    }
    $newfile = "mp3/" . $counter . "phrase" . "4.mp3";
    if (!copy($file, $newfile)) {
        echo "не удалось скопировать {$file}...\n";
    }
    //	echo '<p>'.$value.'</p>';
}
$counter = 0;
foreach ($xml->translation as $value) {
    if ($counter > 99) {
        break;
    }
    $counter++;
    savePhrase($value, $lang, "mp3/" . $counter . "phrase" . "3");
    //	echo '<p>'.$value.'</p>';
}
foreach (glob("uploads/*.*") as $filename) {
    unlink($filename);
}
$zip = new ZipArchive();
$ret = $zip->open('mp3.zip', ZipArchive::OVERWRITE);
if ($ret !== TRUE) {
    printf('Ошибка с кодом %d', $ret);
} else {
    // $options = array('add_path' => 'mp3/', 'remove_all_path' => TRUE);
    $zip->addGlob('mp3/*.mp3');
    $zip->close();
    echo '<a href="mp3.zip" download="mp3.zip">mp3.zip</a>';
}