本文整理汇总了PHP中Zip::getZipData方法的典型用法代码示例。如果您正苦于以下问题:PHP Zip::getZipData方法的具体用法?PHP Zip::getZipData怎么用?PHP Zip::getZipData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zip
的用法示例。
在下文中一共展示了Zip::getZipData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preprocessUtil
public function preprocessUtil($content, $file)
{
if (substr($file, -5) == '.scss') {
$config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions();
$cp = defined('CACHE_DIR') ? CACHE_DIR : 'pc';
$host = @$config['util']['host'];
$path = PUBLIC_PATH . '/img';
$d = array(basename($file) => md5(file_get_contents($file)));
if (!function_exists('recursive_scss')) {
function recursive_scss($path, $dir, &$d)
{
$cur = $path . ($dir ? '/' . $dir : '');
foreach (scandir($cur) as $fn) {
if ($fn == '.' || $fn == '..') {
continue;
}
if (is_dir($cur . '/' . $fn) && !in_array($fn, array('font'))) {
recursive_scss($path, $dir . ($dir ? '/' : '') . $fn, $d);
} else {
if (preg_match('/\\.(' . ($dir == 'sprites' ? 'png|' : '') . 'scss)/i', $fn)) {
$d[$dir . ($dir ? '/' : '') . $fn] = md5(file_get_contents($cur . '/' . $fn));
}
}
}
}
}
recursive_scss($path, '', $d);
if ($d) {
$res = file_get_contents($host . '/x/scss/ch/get/host/' . $_SERVER['HTTP_HOST'] . '/file/' . basename($file));
if ($res) {
if (!class_exists('Zip')) {
require 'Zkernel/Other/Lib/ekernel/lib/Zip.php';
}
$zip = new Zip();
$res = json_decode($res, true);
$cnt = 0;
foreach ($d as $k => $v) {
if ($v != @$res[$k]) {
$zip->addFile(file_get_contents($path . '/' . $k), $k);
$cnt++;
}
}
if ($cnt) {
$data = urlencode($zip->getZipData());
$context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: multipart/form-data' . "\r\n" . 'Content-Length: ' . strlen($data) . "\r\n", 'content' => $data)));
$res = file_get_contents($host . '/x/scss/ch/set/host/' . $_SERVER['HTTP_HOST'] . '/file/' . basename($file), false, $context);
if ($res) {
$res = json_decode($res, true);
file_put_contents(PUBLIC_PATH . '/' . $cp . '/css/temp.zip', urldecode($res['data']));
require 'Zkernel/Other/Lib/ekernel/lib/Unzip.php';
$zip = new Unzip();
$zip->extract(PUBLIC_PATH . '/' . $cp . '/css/temp.zip', PUBLIC_PATH . '/' . $cp . '/css');
unlink(PUBLIC_PATH . '/' . $cp . '/css/temp.zip');
$nfn = str_replace('.scss', '.css', basename($file));
$content = @file_get_contents(PUBLIC_PATH . '/' . $cp . '/css/' . $nfn);
unlink(PUBLIC_PATH . '/' . $cp . '/css/' . $nfn);
}
}
}
}
}
return $content;
}
示例2: strlen
$zip = new Zip();
$zip->setZipFile("ZipExample.zip");
$zip->setComment("Example Zip file.\nCreated on " . date('l jS \\of F Y h:i:s A'));
$zip->addFile("Hello World!", "hello.txt");
@($handle = opendir($fileDir));
if ($handle) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
if (strpos($file, ".html") !== false) {
$pathData = pathinfo($fileDir . $file);
$fileName = $pathData['filename'];
$zip->addFile(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file));
}
}
}
$zip->finalize();
// as we are not using getZipData or getZipFile, we need to call finalize ourselves.
$zip->setZipFile("ZipExample2.zip");
?>
<html>
<head>
<title>Zip Test</title>
</head>
<body>
<h1>Zip Test</h1>
<p>Zip files saved, length is <?php
echo strlen($zip->getZipData());
?>
bytes.</p>
</body>
</html>
示例3: preprocess_util
public function preprocess_util($content, $file)
{
if (substr($file, -5) == '.scss') {
$config = application::get_instance()->config->util;
$path = PATH_ROOT . '/img';
$d = array(basename($file) => md5(file_get_contents($file)));
if (!function_exists('recursive_scss')) {
function recursive_scss($path, $dir, &$d)
{
$cur = $path . ($dir ? '/' . $dir : '');
foreach (scandir($cur) as $fn) {
if ($fn == '.' || $fn == '..') {
continue;
}
if (is_dir($cur . '/' . $fn) && !in_array($fn, array('font'))) {
recursive_scss($path, $dir . ($dir ? '/' : '') . $fn, $d);
} else {
if (preg_match('/\\.(' . ($dir == 'sprites' ? 'png|' : '') . 'scss)/i', $fn)) {
$d[$dir . ($dir ? '/' : '') . $fn] = md5(file_get_contents($cur . '/' . $fn));
}
}
}
}
}
recursive_scss($path, '', $d);
if ($d) {
$res = file_get_contents($config->host . '/x/scss/ch/get/host/' . $_SERVER['HTTP_HOST'] . '/ip/' . $_SERVER['REMOTE_ADDR'] . '/file/' . basename($file));
if ($res) {
if (!class_exists('Zip')) {
require PATH_ROOT . '/' . DIR_LIBRARY . '/lib/Zip.php';
}
$zip = new Zip();
$res = json_decode($res, true);
foreach ($d as $k => $v) {
if ($v != @$res[$k]) {
$zip->addFile(file_get_contents($path . '/' . $k), $k);
}
}
$data = urlencode($zip->getZipData());
$context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: multipart/form-data' . "\r\n" . 'Content-Length: ' . strlen($data) . "\r\n", 'content' => $data)));
$res = file_get_contents($config->host . '/x/scss/ch/set/host/' . $_SERVER['HTTP_HOST'] . '/ip/' . $_SERVER['REMOTE_ADDR'] . '/file/' . basename($file), false, $context);
if ($res) {
$res = json_decode($res, true);
file_put_contents(PATH_ROOT . '/' . DIR_CACHE . '/css/temp.zip', urldecode($res['data']));
require PATH_ROOT . '/' . DIR_LIBRARY . '/lib/Unzip.php';
$zip = new Unzip();
$zip->extract(PATH_ROOT . '/' . DIR_CACHE . '/css/temp.zip', PATH_ROOT . '/' . DIR_CACHE . '/css');
unlink(PATH_ROOT . '/' . DIR_CACHE . '/css/temp.zip');
$nfn = str_replace('.scss', '.css', basename($file));
$content = @file_get_contents(PATH_ROOT . '/' . DIR_CACHE . '/css/' . $nfn);
unlink(PATH_ROOT . '/' . DIR_CACHE . '/css/' . $nfn);
}
}
}
}
return $content;
}
示例4: preprocess_scss
public function preprocess_scss($content, $file, $options = array())
{
$opt = $this->_scss;
if ($options && !is_array($options)) {
$options = array();
}
if ($options) {
$this->_check_options($options);
$opt = array_merge($opt, $options);
}
// process scss file content
$res = $this->_preprocess_scss_content($content, $file);
// find all images from images_dir
$images = array();
$images_dir = trim(dirname($file) . '/' . rtrim($opt['images_dir'], './'), '/');
$this->_preprocess_scss_image($images_dir, '', $images);
// zip scss file and all images
$zip = new Zip();
$zip->addFile($res, 'sass/style.scss');
if ($images) {
foreach ($images as $el) {
$zip->addFile($this->_read_file(ltrim($images_dir . '/', '/') . $el), 'images/' . $el);
}
}
// preparing options for remote call
$opt['file'] = basename($file);
$opt['images_dir'] = '__cache_dir__';
// cleaning gen images cache
$this->_cache_purge('images/' . $opt['file']);
// call api
$result = $this->scss($zip->getZipData(), $opt);
$content = $result['content'];
// unzip images and replace their names in content
if ($result['images']) {
$dir = $this->_path_root . '/' . $this->_cache_dir . '/images/' . $opt['file'];
$this->_cache_save('images/' . $opt['file'], 'temp', $result['images'], 'zip');
try {
$zip = new Unzip();
$zip->extract($dir . '/temp.zip', $dir);
$zip->close();
unlink($dir . '/temp.zip');
} catch (\Exception $ex) {
}
$content = str_replace('__cache_dir__', '/' . $this->_cache_dir . '/images/' . $opt['file'], $content);
}
return $content;
}