} else { // build a zip archive include_once '../shared/zipfile.php'; $zipfile = new zipfile(); // get related files from the database $items = array(); if (isset($type) && isset($id)) { $items = Files::list_by_date_for_anchor($type . ':' . $id, 0, 20, 'raw'); } // archive each file $file_path = $context['path_to_root'] . Files::get_path($type . ':' . $id); foreach ($items as $id => $attributes) { // read file content if ($content = Safe::file_get_contents($file_path . '/' . $attributes['file_name'], 'rb')) { // add the binary data $zipfile->deflate($attributes['file_name'], Safe::filemtime($file_path . '/' . $attributes['file_name']), $content); } } // // transfer to the user agent // // send the archive content if ($archive = $zipfile->get()) { // suggest a download Safe::header('Content-Type: application/octet-stream'); // suggest a name for the saved file $file_name = utf8::to_ascii($item['title']) . '.zip'; Safe::header('Content-Disposition: attachment; filename="' . str_replace('"', '', $file_name) . '"'); // file size Safe::header('Content-Length: ' . strlen($archive)); // already encoded
// place all files into a single directory --fixed time to allow cacheability $zipfile->store('yacs/', 0); // process every reference file $all_files = array(); $index = 0; foreach ($references as $reference) { // let's go list($path, $file) = $reference; if (strlen(trim($path)) > 0) { $file = $path . '/' . $file; } // read file content if (($content = Safe::file_get_contents($file_path . $file)) !== FALSE) { // compress textual content if ($content && preg_match('/\\.(css|htc|htm|html|include|js|mo|php|po|pot|sql|txt|xml)$/i', $file)) { $zipfile->deflate('yacs/' . $file, Safe::filemtime($file_path . $file), $content); } else { $zipfile->store('yacs/' . $file, Safe::filemtime($file_path . $file), $content); } // to be included in tar file as well $all_files[] = $file_path . $file; } else { $context['text'] .= BR . 'cannot read ' . $file_path . $file; } // avoid timeouts if (!($index++ % 50)) { Safe::set_time_limit(30); SQL::ping(); } } // save the zipfile