简体   繁体   中英

Save as zip instead tar

Is it possible to change it (archive as tar) to archive as zip? I am not good in php

if (ARCHIVE && isset($_GET['archive']))
{
    $log -> add_entry('Directory archived');
    $outfile = Item::get_basename($subdir);
    if ($outfile == '' || $outfile == '.')
    {
        $outfile = 'base_dir';
    }
    $mime = new MimeType('.tar');
    header('Content-Type: ' . $mime -> __toString());
    header('Content-Disposition: attachment; filename="'
    . $outfile . '.tar"');
    @set_time_limit(0);
    $list = new DirectoryList($dir);
    $tar = new Tar($list, $outfile, strlen($dir));
    die();
}

Yes, you can use the PHP ZipArchive object.

ie (from source link) :

<?php

$files = array('image.jpeg','text.txt','music.wav');
$zipname = 'enter_any_name_for_the_zipped_file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
  $zip->addFile($file);
}
$zip->close();

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM