本文整理汇总了PHP中Zip类的典型用法代码示例。如果您正苦于以下问题:PHP Zip类的具体用法?PHP Zip怎么用?PHP Zip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract
public function extract($zip_file)
{
$posts = array();
if (!$zip_file) {
return $posts;
}
$z = new Zip();
$result = $z->Extract($zip_file, ".");
if (!$result) {
$posts;
}
foreach ($result as $key => $value) {
if (!self::is_file_with_extension($key, 'xliff')) {
continue;
}
$xliff = self::get_xliff($value);
$translation_item = self::get_translation_item($xliff->children());
if (!self::is_valid($translation_item)) {
continue;
}
$post = get_post($translation_item['id']);
if (!$post) {
continue;
}
if ($post->post_title != $translation_item['title']) {
$post->post_title = $translation_item['title'];
}
if ($post->post_content != $translation_item['content']) {
$post->post_content = $translation_item['content'];
}
array_push($posts, $post);
}
return $posts;
}
示例2: export
public static function export($idstr)
{
$idArr = is_array($idstr) ? $idstr : explode(",", $idstr);
if (1 < count($idArr)) {
$zip = new Zip();
$exportFileName = Ibos::lang("Form export file pack", "workflow.default", array("{date}" => date("Y-m-d")));
$zipFileName = FileUtil::getTempPath() . "/" . TIMESTAMP . ".zip";
foreach ($idArr as $id) {
$form = self::handleExportSingleForm($id);
$zip->addFile($form["content"], sprintf("%s.html", ConvertUtil::iIconv($form["title"], CHARSET, "gbk")));
}
$fp = fopen($zipFileName, "w");
if (@fwrite($fp, $zip->file()) !== false) {
header("Cache-control: private");
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Content-Length: " . sprintf("%u", FileUtil::fileSize($zipFileName)));
header("Content-Disposition: attachment; filename=" . $exportFileName . ".zip");
readfile($zipFileName);
exit;
}
} else {
$id = implode(",", $idArr);
$form = self::handleExportSingleForm($id);
ob_end_clean();
header("Cache-control: private");
header("Content-type: text/plain");
header("Accept-Ranges: bytes");
header("Accept-Length: " . strlen($form["content"]));
header("Content-Disposition: attachment; filename=" . $form["title"] . ".html");
echo $form["content"];
}
}
示例3: index
public function index()
{
// Define directory separator
define(MYDS, '/');
if ($_POST['submit']) {
$yui = new Yui();
$yui->compressor_dir = '/assets' . DS . 'compressor' . DS;
$yui->params = array('nomunge' => $_POST['nomunge'], 'preserve-semi' => $_POST['preserve-semi'], 'disable-optimizations' => $_POST['disable-optimizations']);
$yui->execute(array_merge($_FILES, $_POST));
$this->vars['error'] = $yui->error;
$file_loc = $yui->compressed['dir'] . $yui->compressed['file'];
$filename = $yui->compressed['file'];
$filename_zip = current(explode('.', $yui->compressed['file'])) . '.zip';
$zip_file_with_path = $yui->compressed['dir'] . $filename_zip;
if ($_POST['zipped'] === "1") {
$zip = new Zip();
$zip->addFile($file_loc, $filename);
$zip->save($zip_file_with_path);
$this->vars['zipped_file'] = '<a href="' . $zip_file_with_path . '" target="_blank">' . $filename_zip . '</a>';
}
$this->vars['compressed_file'] = '<a href="' . $file_loc . '" target="_blank">' . $filename . '</a>';
}
$this->layout_vars['page_title'] = 'YUI Compression tool';
$this->display('home/index', $this->vars);
}
示例4: upload
function upload($incVersion)
{
$vs = qg::remoteGet($this->name);
if (!is_dir(sysPATH . $this->name)) {
return false;
}
$v = explode('.', $vs['version']);
$v = @array((int) $v[0], (int) $v[1], (int) $v[2]);
foreach ($v as $i => $vp) {
if ($i >= $incVersion) {
$v[$i] = 0;
}
}
isset($v[$incVersion - 1]) && ++$v[$incVersion - 1];
$vs['version'] = implode('.', $v);
$tmpFile = appPATH . 'cache/tmp/module_export1.zip';
is_file($tmpFile) && unlink($tmpFile);
// zzz unlink???
ini_set('max_execution_time', '600');
$zip = new Zip();
$zip->open($tmpFile, Zip::CREATE);
$zip->addDir(sysPATH . $this->name, null, '/(\\.svn)|(zzz)/');
$zip->close();
$vs['size'] = filesize($tmpFile);
$this->local_version = $vs['version'];
@qg::Ftp()->mkdir('/module/' . $this->name . '/');
qg::Ftp()->put('/module/' . $this->name . '/' . $vs['version'] . '.zip', $tmpFile, FTP_BINARY);
qg::remoteSet($this->name, $vs);
return $vs['version'];
}
示例5: compress
/**
* Compresses the directory with ZIP.
* @param string $fileName The file name of the ZIP archive.
* @param int $flags [optional] The mode to use to open the archive.
* @return mixed The ZIP archive or an error code on failure.
*/
public function compress($fileName, $flags = \ZipArchive::CREATE)
{
$zip = new Zip();
if (($res = $zip->open($fileName, $flags)) === true) {
$zip->addDir($this->path);
$zip->close();
return $zip;
}
return $res;
}
示例6: run
function run($args)
{
if (empty($args[1])) {
echo $this->getHelp();
return;
}
$path = $args[0];
$version = $args[1];
echo "Preparing {$path} release.\n";
require dirname(__FILE__) . '/GenerateDocsCommand.php';
$docProcessor = new GenerateDocsCommand($this->getName(), $this->getCommandRunner());
$outFiles = $docProcessor->processDocuments($path);
// copy extension dir to temp
$extPath = Yii::getPathOfAlias('ext') . '/' . $path;
$copiedExtRoot = Yii::getPathOfAlias('application.runtime.extension');
echo "Removing {$copiedExtRoot}.\n";
if (file_exists($copiedExtRoot)) {
$this->recursiveDelete($copiedExtRoot);
}
$copiedExtPath = $copiedExtRoot . '/' . $path;
if (!file_exists($copiedExtPath)) {
mkdir($copiedExtPath, 0777, true);
}
echo "Copying extension files from {$extPath} to {$copiedExtPath}.\n";
CFileHelper::copyDirectory($extPath, $copiedExtPath, array('exclude' => array('.svn', 'readme_en.txt', 'readme_ru.txt')));
echo "Copying documentation to {$copiedExtPath}.\n";
foreach ($outFiles as $file) {
copy($file, $copiedExtPath . '/' . basename($file));
}
$pathExp = explode('/', $path);
$zipName = end($pathExp) . '_' . $version . '.zip';
$releasePath = Yii::getPathOfAlias('application.releases');
if (!file_exists($releasePath)) {
mkdir($releasePath, 0777, true);
}
$zipPath = "{$releasePath}/{$zipName}";
if (file_exists($zipPath)) {
unlink($zipPath);
}
//touch($zipPath);
echo "Creating Zip {$zipPath}.\n";
require dirname(__FILE__) . '/Zip.php';
$zip = new Zip();
if ($zip->open($zipPath, ZipArchive::OVERWRITE | ZipArchive::CREATE) !== TRUE) {
die("Failed to open Zip {$zipPath}.\n");
}
if (!$zip->addDir($copiedExtRoot)) {
die("Failed adding {$copiedExtRoot} to Zip.\n");
}
if ($zip->close()) {
echo "Done.\n";
} else {
die("Failed to write Zip {$zipPath}.\n");
}
}
示例7: download
static function download($name, $beta = false)
{
$vs = self::remoteGet($name, $beta);
self::ftp()->get(appPATH . 'cache/tmp/pri/remoteModule.zip', '/module/' . $name . '/' . $vs['version'] . '.zip', FTP_BINARY);
$zip = new Zip();
$go = $zip->open(appPATH . 'cache/tmp/pri/remoteModule.zip');
if (!$go) {
return;
}
rrmdir(sysPATH . $name);
$zip->extractTo(sysPATH);
$zip->close();
return $vs;
}
示例8: isPOMExists
/**
* Megnézi, hogy a paraméterben kapott zip file-ban létezik e a pom.xml file.
* @param string $pin_FileName A vizsgált zip file
* @return bool Létezik e a pom vagy sem
*/
public static function isPOMExists(string $pin_FileName) : bool
{
$obj_Zip = new Zip();
$obj_Zip->setZipFile($pin_FileName);
(array) ($loc_Zip = $obj_Zip->getZipFileContent());
(array) ($loc_Tmp = array());
foreach ($loc_Zip as $loc_File) {
$loc_Tmp = array_merge($loc_Tmp, explode('/', $loc_File));
}
if (in_array('pom.xml', $loc_Tmp)) {
return true;
}
return false;
}
示例9: install
public function install($filename)
{
$src = ROOT . '/sys/tmp/' . $filename;
$dest = ROOT . '/sys/tmp/install_plugin/';
Zip::extractZip($src, $dest);
if (!file_exists($dest)) {
$this->errors = __('Some error occurred');
return false;
}
$tmp_plugin_path = glob($dest . '*', GLOB_ONLYDIR);
$tmp_plugin_path = $tmp_plugin_path[0];
$plugin_basename = substr(strrchr($tmp_plugin_path, '/'), 1);
$plugin_path = ROOT . '/sys/plugins/' . $plugin_basename;
copyr($dest, ROOT . '/sys/plugins/', 0755);
$this->files = getDirFiles($plugin_path);
if (file_exists($plugin_path . '/config.dat')) {
$config = json_decode(file_get_contents($plugin_path . '/config.dat'), true);
include_once $plugin_path . '/index.php';
$className = $config['className'];
$obj = new $className(null);
if (method_exists($obj, 'install')) {
$obj->install();
}
}
_unlink($src);
_unlink($dest);
return true;
}
示例10: action_zip
public function action_zip($articulo_id = null)
{
is_null($articulo_id) and Response::redirect('diagramador');
$articulos = Model_Articulo::find('all', array('related' => array('fotos', 'seccion'), 'where' => array(array('id', '=', $articulo_id))));
$files_to_zip = array();
$archivo_informacion = '';
foreach ($articulos as $articulo) {
$archivo_informacion .= "Nombre del Articulo: " . $articulo->nombre . "\n";
$archivo_informacion .= "Seccion del Articulo: " . $articulo->seccion->descripcion . "\n";
$archivo_informacion .= "Fecha del Articulo: " . date('Y-m-d H:i:s', $articulo->fecha_publicacion) . "\n";
$archivo_informacion .= "\n ==========================\n";
foreach ($articulo->fotos as $foto) {
if ($foto->estado == 1) {
array_push($files_to_zip, $foto->imagen);
$nombre_archivo = str_ireplace(".jpg", "-" . $articulo->pagina->descripcion . ".jpg", $foto->imagen);
$pieces = explode("/", $nombre_archivo);
$count_foto = count($pieces);
$nombre_archivo = $pieces[$count_foto - 1];
$archivo_informacion .= $nombre_archivo . "\n" . "Medida: " . $foto->dimension->descipcion . "\n" . "Pagina: " . $articulo->pagina->descripcion . "\n ==========================\n";
}
}
}
$time = time();
File::create(DOCROOT . "zip/", "info_{$articulo_id}_{$time}.txt", $archivo_informacion);
array_push($files_to_zip, "/gr/public/zip/info_{$articulo_id}_{$time}.txt");
Zip::create_zip($files_to_zip, $articulo_id, true, $time, $articulo->pagina->descripcion);
}
示例11: download
/**
* Download zipfile.
*
* @param array $files
* @param string $filename
*
* @return string
*/
public function download($files, $filename)
{
// Get assets
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->id = $files;
$criteria->limit = null;
$assets = $criteria->find();
// Set destination zip
$destZip = craft()->path->getTempPath() . $filename . '_' . time() . '.zip';
// Create the zipfile
IOHelper::createFile($destZip);
// Loop through assets
foreach ($assets as $asset) {
// Get asset source
$source = $asset->getSource();
// Get asset source type
$sourceType = $source->getSourceType();
// Get asset file
$file = $sourceType->getLocalCopy($asset);
// Add to zip
Zip::add($destZip, $file, dirname($file));
}
// Return zip destination
return $destZip;
}
示例12: getPluginInfo
/**
* @param mixed $plugin
* @throws \RuntimeException
* @return array
*/
public function getPluginInfo($plugin)
{
switch (true) {
case is_array($plugin):
$backend = new ArrayTestCase();
break;
case is_dir($plugin):
$backend = new Directory();
break;
case is_file($plugin):
$backend = new Zip();
break;
default:
throw new \RuntimeException("Could not automatically detect type of given plugin");
}
return $backend->getPluginInfo($plugin);
}
示例13: rebuildZipFile
public function rebuildZipFile($workshopId)
{
$documents = $this->getDocumentsForWorkshop($workshopId);
$config = Zend_Registry::get('config');
if (!is_readable($config->user->fileUploadPathWorkshop->val)) {
throw new Ot_Exception_Data('Target directory is not readable');
}
$zip = new Zip($config->user->fileUploadPathWorkshop->val . '/' . $workshopId . '/all_handouts.zip');
$filesToAdd = array();
foreach ($documents as $d) {
$target = $config->user->fileUploadPathWorkshop->val . '/' . $workshopId . '/' . $d['name'];
if (is_file($target)) {
$filesToAdd[] = $target;
} else {
throw new Ot_Exception_Data('File not found: ' . $target);
}
}
$zip->addFiles($filesToAdd);
$zip->createZipFile();
}
示例14: create_zip_Zip
function create_zip_Zip($files = array(), $destination = '')
{
if (count($files)) {
//create the archive
if (file_exists($destination)) {
unlink($destination);
}
$zip = new Zip();
$zip->setZipFile($destination);
foreach ($files as $file) {
$zip->addFile(file_get_contents($file), str_replace('/', '', strrchr($file, '/')));
}
$zip->finalize();
$zip->setZipFile($destination);
//check to make sure the file exists
return (string) file_exists($destination);
} else {
return "No valid files found. Exiting<br/>";
}
}
示例15: __construct
/**
* Create a Zip object and store the query results
*
* @param mysqli_result $QueryResult results from a query on the collector pages
* @param string $Title name of the collection that will be created
* @param string $AnnounceURL URL to add to the created torrents
*/
public function __construct(&$QueryResult, $Title)
{
G::$Cache->InternalCache = false;
// The internal cache is almost completely useless for this
Zip::unlimit();
// Need more memory and longer timeout
$this->QueryResult = $QueryResult;
$this->Title = $Title;
$this->User = G::$LoggedUser;
$this->AnnounceURL = ANNOUNCE_URL . '/' . G::$LoggedUser['torrent_pass'] . '/announce';
$this->Zip = new Zip(Misc::file_string($Title));
}