本文整理汇总了PHP中zipfile::deflate方法的典型用法代码示例。如果您正苦于以下问题:PHP zipfile::deflate方法的具体用法?PHP zipfile::deflate怎么用?PHP zipfile::deflate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zipfile
的用法示例。
在下文中一共展示了zipfile::deflate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: zipfile
} 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
示例2: array
// 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