本文整理汇总了PHP中Zip::finalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Zip::finalize方法的具体用法?PHP Zip::finalize怎么用?PHP Zip::finalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zip
的用法示例。
在下文中一共展示了Zip::finalize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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/>";
}
}
示例2: ZipArchive
// Preferrably use the zip extension
if (extension_loaded('zip')) {
$save_to_zip = $export_dir . $export_name . '.zip';
$zip = new ZipArchive();
$res = $zip->open($save_to_zip, ZipArchive::CREATE);
if ($res === TRUE) {
$zip->addFile($save_to, "{$export_name}.xml");
$zip->close();
} else {
die("{$hesklang['eZIP']} <{$save_to_zip}>\n");
}
} elseif (class_exists('ZipArchive')) {
require HESK_PATH . 'inc/zip/Zip.php';
$zip = new Zip();
$zip->addLargeFile($save_to, "{$export_name}.xml");
$zip->finalize();
$zip->setZipFile($save_to_zip);
} else {
require HESK_PATH . 'inc/zip/pclzip.lib.php';
$zip = new PclZip($save_to_zip);
$zip->add($save_to, PCLZIP_OPT_REMOVE_ALL_PATH);
}
// Delete XML, just leave the Zip archive
hesk_unlink($save_to);
// Echo memory peak usage
$flush_me .= hesk_date() . " | " . sprintf($hesklang['pmem'], @memory_get_peak_usage(true) / 1048576) . "<br />\r\n";
// We're done!
$flush_me .= hesk_date() . " | {$hesklang['fZIP']}<br /><br />";
$flush_me .= '<a href="' . $save_to_zip . '">' . $hesklang['ch2d'] . "</a>\n";
} else {
hesk_unlink($save_to);
示例3: backup_items
public function backup_items($items)
{
$dir = SNS_BACKUPS_PATH . $this->filename;
if (!class_exists('Zip', false)) {
require_once SNS_LIB_PATH . 'Zip.php';
}
$warns = array('not_readable' => array());
$zip = new Zip();
$zip->setZipFile($dir . '.zip');
self::$zipFile = $zip;
foreach ($items as $name => $path) {
if ($name == Sns_Option::DB) {
$sql_file = SNS_BACKUPS_PATH . 'wp_dump.sql';
Sns_Log::log_action('Exporting DB');
Sns_Backup::export_db($sql_file);
Sns_Log::log_action('Exporting DB', SNS_LOG_END);
$stream = @fopen($sql_file, 'rb');
if ($stream) {
$zip->addLargeFile($stream, 'wp_dump.sql');
}
@unlink($sql_file);
continue;
}
Sns_Log::log_action('Backup item - ' . $name);
$itemZip = new Zip();
$itemZip->setZipFile(SNS_BACKUPS_PATH . $name . '.zip');
$path = realpath($path);
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS));
$exclude = array(realpath(SNS_BACKUP_ROOT), realpath(SNS_BACKUPS_PATH), realpath(WP_CONTENT_DIR . SNS_DS . 'debug.log'));
for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
$file = $iterator->current();
$continue = false;
foreach ($exclude as $excludeFile) {
if (strpos($file, $excludeFile) !== false) {
$continue = true;
}
}
if ($continue) {
continue;
}
if (file_exists($file) && is_readable($file)) {
$stream = @fopen($file, 'rb');
if ($stream) {
$file = substr($file, strlen($path));
$itemZip->addLargeFile($stream, $file);
}
} else {
$warns['not_readable'][] = $file;
}
}
$itemZip->finalize();
$stream = @fopen(SNS_BACKUPS_PATH . $name . '.zip', 'rb');
if ($stream) {
$zip->addLargeFile($stream, $name . '.zip');
}
@unlink(SNS_BACKUPS_PATH . $name . '.zip');
Sns_Log::log_action('Backup item - ' . $name, SNS_LOG_END);
}
Sns_Log::log_action('Summarize item backups');
$zip->finalize();
Sns_Log::log_action('Summarize item backups', SNS_LOG_END);
$this->hash;
$this->filename;
$this->save();
return $warns;
}
示例4: getArchive
/**
* Creates a new archive with the specified name and files
* @param string $name Path to the archive with name and extension
* @param array $files A numeric array of files
* @param string $replace
* @param string $fullPath
* @return int How many files has been successfully handled
*/
public function getArchive($name, array $files, $replace = ABSPATH, $fullPath = false)
{
set_time_limit(300);
if (!class_exists('Zip', false)) {
/** @var backupBup $backup */
$backup = $this->getModule();
$backup->loadLibrary('zip');
}
$zip = new Zip();
$zip->setZipFile($name);
if ($fullPath) {
$absPath = null;
} else {
$absPath = str_replace('/', DS, ABSPATH);
}
foreach ($files as $filename) {
$file = $absPath . $filename;
if ($fullPath) {
$file = str_replace('\\\\', DS, $filename);
}
if (file_exists($file) && is_readable($file) && (substr(basename($file), 0, 3) != 'pcl' && substr($file, -2) != 'gz')) {
$stream = @fopen($file, 'rb');
if ($stream) {
$zip->addLargeFile($stream, $filename);
}
}
}
$zip->finalize();
if (false !== strpos($name, 'backup_')) {
// if backup created - remove all temporary files from tmp directory
$this->clearTmpDirectory();
}
/* backward */
return rand(100, 1000);
}
示例5: scanner
//.........这里部分代码省略.........
}
exit;
}
} else {
$error_msg = 'Error: ZipArchive class is not exist.';
if (self::$debug) {
self::DebugLog($error_msg);
}
}
$error_msg = 'ZipArchive method - finished';
if (self::$debug) {
self::DebugLog($error_msg);
}
// Check if zip file exists
if (!file_exists($file_zip)) {
$error_msg = 'Error: zip file is not exists. Use OwnZipClass';
if (self::$debug) {
self::DebugLog($error_msg);
}
$error_msg = 'OwnZipClass method - started';
if (self::$debug) {
self::DebugLog($error_msg);
}
$zip = new Zip();
$zip->setZipFile($file_zip);
foreach ($files_list as $file_name_short) {
$file_name = trim($this->scan_path . $file_name_short);
$handle = fopen($file_name, "r");
if (filesize($file_name) > 0) {
$zip->addFile(fread($handle, filesize($file_name)), $file_name_short, filectime($file_name), NULL, TRUE, Zip::getFileExtAttr($file_name));
}
fclose($handle);
}
$zip->finalize();
$error_msg = 'OwnZipClass method - finished';
if (self::$debug) {
self::DebugLog($error_msg);
}
$ssh_flag = false;
}
}
// Update progress
$current_task += 1;
self::UpdateProgressValue($current_task, $total_tasks, 'Collecting information about the files.');
/**
* Send files to SG server
*/
if ($ssh_flag) {
$archive_filename = $this->tmp_dir . "pack.tar";
$archive_format = 'tar';
} else {
$archive_filename = $this->tmp_dir . "pack.zip";
$archive_format = 'zip';
}
$error_msg = 'Pack file: ' . $archive_filename;
if (self::$debug) {
self::DebugLog($error_msg);
}
// Check if pack file is exist
if (file_exists($archive_filename) === false) {
$error_msg = 'Error: Pack file is not exist. Probably not enough space on the server.';
if (self::$debug) {
self::DebugLog($error_msg);
}
echo $error_msg;
exit;
示例6: createDownloadPackage
//.........这里部分代码省略.........
'item_id' => $documentId,
'doc_id' => $documentId,
'value' => $fileObject->size,
'reference' => $fileId . ($version ? ':' . $version : '')
);
JUDownloadFrontHelperLog::addLog($logData);
}
}
}
// Only support download file/document, invalid type -> return false
else
{
return false;
}
$serverTime = JFactory::getDate()->toSql();
$serverTimeStamp = strtotime($serverTime);
// Store ID of download file(s) into session
if ($noCountingDownloadSecond > 0)
{
$storeIdArray = (array) $app->getUserState('com_judownload.download.storeid');
$storeIdArray[$serverTimeStamp] = $storeId;
$storeIdArray = array_unique($storeIdArray);
$app->setUserState('com_judownload.download.storeid', $storeIdArray);
}
// Last download time to calculate download interval
$session = JFactory::getSession();
$session->set('judl-last-download-time', $serverTime);
// If use zip class to zip files, set comment then close the archive
if ($zipFile)
{
// Set comment for zip file
$zip->setComment($zipComment);
// Close the archive
$zip->finalize();
}
// Send email by event for each document when download
$docIdArray = array();
if ($type == 'file')
{
$docIdArray[] = $parentId;
}
else
{
$docIdArray = $itemIdArray;
}
$docIdArray = array_unique($docIdArray);
//Send mail by event
foreach ($docIdArray AS $docId)
{
JUDownloadFrontHelperMail::sendEmailByEvent('document.download', $docId);
}
// Download ZIPPED file
if ($zipFile)
{
// Directly download(from zip resource by PHP)
$resourceFilePath = $zip->getZipFile();
$transport = 'php';
$speed = (int) $params->get('max_download_speed', 200);
$resume = $params->get('resume_download', 1);
$downloadMultiParts = $params->get('download_multi_parts', 1);
$downloadResult = JUDownloadHelper::downloadFile($resourceFilePath, $zipFileName, $transport, $speed, $resume, $downloadMultiParts);
if ($downloadResult !== true)
{
$this->setError($downloadResult);
return false;
}
}
// Download ONE NO ZIPPED file, in this case $zipFileName is the download file name, file can be zip file or not
else
{
// Directly download
$transport = $downloadOneFileNoZippedMode;
$speed = (int) $params->get('max_download_speed', 200);
$resume = $params->get('resume_download', 1);
$downloadMultiParts = $params->get('download_multi_parts', 1);
$downloadResult = JUDownloadHelper::downloadFile($physicalFilePath, $zipFileName, $transport, $speed, $resume, $downloadMultiParts);
if ($downloadResult !== true)
{
$this->setError($downloadResult);
return false;
}
}
return true;
}
示例7: Zip
function download_archive()
{
global $wpdb, $current_user;
if (!is_user_logged_in()) {
exit;
}
$user_ID = $_GET['id'];
$dir = '' . SP_CDM_UPLOADS_DIR . '' . $user_ID . '/';
$path = '' . SP_CDM_UPLOADS_DIR_URL . '' . $user_ID . '/';
$return_file = "Account.zip";
$zip = new Zip();
$r = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "sp_cu where uid = %d order by date desc", $user_ID), ARRAY_A);
//@unlink($dir.$return_file);
for ($i = 0; $i < count($r); $i++) {
$zip->addFile(file_get_contents($dir . $r[$i]['file']), $r[$i]['file'], filectime($dir . $r[$i]['file']));
}
$zip->finalize();
// as we are not using getZipData or getZipFile, we need to call finalize ourselves.
$zip->setZipFile($dir . $return_file);
header("Location: " . $path . $return_file . "");
}
示例8: getArchive
/**
* Creates a new archive with the specified name and files
* @param string $name Path to the archive with name and extension
* @param array $files A numeric array of files
* @param string $replace
* @return int How many files has been successfully handled
*/
public function getArchive($name, array $files, $replace = ABSPATH)
{
set_time_limit(300);
if (!class_exists('Zip', false)) {
/** @var backupBup $backup */
$backup = $this->getModule();
$backup->loadLibrary('zip');
}
$zip = new Zip();
$zip->setZipFile($name);
foreach ($files as $file) {
$filename = str_replace($replace, '', $file);
if (file_exists($file) && is_readable($file) && (substr(basename($file), 0, 3) != 'pcl' && substr($file, -2) != 'gz')) {
$stream = @fopen($file, 'rb');
if ($stream) {
$zip->addLargeFile($stream, $filename);
}
}
}
$zip->finalize();
/* backward */
return rand(100, 1000);
}
示例9: sp_Admin_uploadFile
function sp_Admin_uploadFile($files, $user_ID)
{
global $wpdb;
$dir = '' . SP_CDM_UPLOADS_DIR . '' . $user_ID . '/';
$count = sp_array_remove_empty($files['dlg-upload-file']['name']);
if ($history == 1) {
$dir = '' . SP_CDM_UPLOADS_DIR . '' . $user_ID . '/';
$filename = '' . sp_client_upload_filename($user_ID) . '' . $files['dlg-upload-file']['name'][0] . '';
$filename = strtolower($filename);
$filename = sanitize_file_name($filename);
$filename = remove_accents($filename);
$target_path = $dir . $filename;
move_uploaded_file($files['dlg-upload-file']['tmp_name'][0], $target_path);
$ext = preg_replace('/^.*\\./', '', $filename);
if (get_option('sp_cu_user_projects_thumbs_pdf') == 1 && class_exists('imagick')) {
$info = new Imagick();
$formats = $info->queryFormats();
if (in_array(strtoupper($ext), $formats)) {
cdm_thumbPdf($target_path);
}
}
return $filename;
} else {
if (count($count) > 1) {
//echo $count;
// echo '<pre>';
//print_r($files);exit;
//echo '</pre>';
$fileTime = date("D, d M Y H:i:s T");
$zip = new Zip();
for ($i = 0; $i < count($files['dlg-upload-file']['name']); $i++) {
if ($files['dlg-upload-file']['error'][$i] == 0) {
$filename = '' . sp_client_upload_filename($user_ID) . '' . $files['dlg-upload-file']['name'][$i] . '';
$filename = strtolower($filename);
$filename = sanitize_file_name($filename);
$filename = remove_accents($filename);
$target_path = $dir . $filename;
move_uploaded_file($files['dlg-upload-file']['tmp_name'][$i], $target_path);
$zip->addFile(file_get_contents($target_path), $filename, filectime($target_path));
}
}
$zip->finalize();
// as we are not using getZipData or getZipFile, we need to call finalize ourselves.
$return_file = "" . rand(100000, 100000000000) . "_Archive.zip";
$zip->setZipFile($dir . $return_file);
return $return_file;
} else {
$dir = '' . SP_CDM_UPLOADS_DIR . '' . $user_ID . '/';
$filename = '' . sp_client_upload_filename($user_ID) . '' . $files['dlg-upload-file']['name'][1] . '';
$filename = strtolower($filename);
$filename = sanitize_file_name($filename);
$filename = remove_accents($filename);
$target_path = $dir . $filename;
move_uploaded_file($files['dlg-upload-file']['tmp_name'][1], $target_path);
$ext = preg_replace('/^.*\\./', '', $filename);
if (get_option('sp_cu_user_projects_thumbs_pdf') == 1 && class_exists('imagick')) {
$info = new Imagick();
$formats = $info->queryFormats();
if (in_array(strtoupper($ext), $formats)) {
cdm_thumbPdf($target_path);
}
}
return $filename;
}
}
}