当前位置: 首页>>代码示例>>PHP>>正文


PHP Zip::addFile方法代码示例

本文整理汇总了PHP中Zip::addFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Zip::addFile方法的具体用法?PHP Zip::addFile怎么用?PHP Zip::addFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zip的用法示例。


在下文中一共展示了Zip::addFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:silentworks,项目名称:the-compressor,代码行数:25,代码来源:HomeController.php

示例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"];
     }
 }
开发者ID:AxelPanda,项目名称:ibos,代码行数:33,代码来源:WfFormUtil.php

示例3: 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/>";
    }
}
开发者ID:StudentLifeMarketingAndDesign,项目名称:krui-wp,代码行数:20,代码来源:downml_settings_page.php

示例4: unlink

if (isset($_GET['export'])) {
    //set_time_limit(0);
    $tmpFile = appPATH . 'cache/tmp/pri/modExport.zip';
    is_file($tmpFile) && unlink($tmpFile);
    $zip = new Zip();
    $zip->open($tmpFile, Zip::CREATE);
    $zip->addDir(appPATH . 'm', null, '/(\\.svn)/');
    $zip->addDir(appPATH . 'qg', null, '/(\\.svn)/');
    foreach (scandir(appPATH) as $file) {
        if (!is_file(appPATH . $file)) {
            continue;
        }
        if ($file === 'error_log') {
            continue;
        }
        $zip->addFile(appPATH . $file, $file);
    }
    /* only custom module:
    	foreach (dbEntry_module::all() as $M) {
    		If ($M->server_time) continue;
    		$zip->addDir(sysPATH.$name, 'm/'.$M->name, '/(\.svn)/');
    	}
    
    	/* add mysql export */
    $structExport = '';
    @mkdir('/tmp/');
    @mkdir('/tmp/qgdbexport1/');
    chmod('/tmp/qgdbexport1/', 0777);
    foreach (D()->Tables() as $T) {
        $file = realpath('/tmp/qgdbexport1/') . '/' . $T . '.csv';
        @unlink($file);
开发者ID:nuxodin,项目名称:shwups-cms-v4,代码行数:31,代码来源:index.php

示例5: backup

 function backup()
 {
     $settings = Plugin::getAllSettings('backup_restore');
     // All of the tablesnames that belong to Wolf CMS core.
     $tablenames = array();
     if (strpos(DB_DSN, 'mysql') !== false) {
         $sql = 'show tables';
     }
     if (strpos(DB_DSN, 'sqlite') !== false) {
         $sql = 'SELECT name FROM SQLITE_MASTER WHERE type="table" ORDER BY name';
     }
     if (strpos(DB_DSN, 'pgsql') !== false) {
         $sql = "select tablename from pg_tables where schemaname='public'";
     }
     Record::logQuery($sql);
     $pdo = Record::getConnection();
     $result = $pdo->query($sql);
     while ($col = $result->fetchColumn()) {
         $tablenames[] = $col;
     }
     // All fields that should be wrapped as CDATA
     $cdata_fields = array('title', 'content', 'content_html');
     // Setup XML for backup
     $xmltext = '<?xml version="1.0" encoding="UTF-8"?><wolfcms></wolfcms>';
     $xmlobj = new SimpleXMLExtended($xmltext);
     $xmlobj->addAttribute('version', CMS_VERSION);
     // Retrieve all database information for placement in XML backup
     global $__CMS_CONN__;
     Record::connection($__CMS_CONN__);
     // Generate XML file entry for each table
     foreach ($tablenames as $tablename) {
         $table = Record::query('SELECT * FROM ' . $tablename);
         $child = $xmlobj->addChild($tablename . 's');
         while ($entry = $table->fetch(PDO::FETCH_ASSOC)) {
             $subchild = $child->addChild($tablename);
             foreach ($entry as $key => $value) {
                 if ($key == 'password' && $settings['pwd'] === '0') {
                     $value = '';
                 }
                 if (in_array($key, $cdata_fields, true)) {
                     $valueChild = $subchild->addCData($key, $value);
                 } else {
                     $valueChild = $subchild->addChild($key, str_replace('&', '&amp;', $value));
                 }
                 if ($value === null) {
                     $valueChild->addAttribute('null', true);
                 }
             }
         }
     }
     // Add XML files entries for all files in upload directory
     if ($settings['backupfiles'] == '1') {
         $dir = realpath(FILES_DIR);
         $this->_backup_directory($xmlobj->addChild('files'), $dir, $dir);
     }
     // Create the XML file
     $file = $xmlobj->asXML();
     $filename = 'wolfcms-backup-' . date($settings['stamp']) . '.' . $settings['extension'];
     // Offer a plain XML file or a zip file for download
     if ($settings['zip'] == '1') {
         // Create a note file
         $note = "---[ NOTES for {$filename} ]---\n\n";
         $note .= "This backup was created for a specific Wolf CMS version, please only restore it\n";
         $note .= "on the same version.\n\n";
         $note .= "When restoring a backup, upload the UNzipped XML backup file, not this zip file.\n\n";
         $note .= 'Created on ' . date('Y-m-d') . ' at ' . date('H:i:s') . ' GTM ' . date('O') . ".\n";
         $note .= 'Created with BackupRestore plugin version ' . BR_VERSION . "\n";
         $note .= 'Created for Wolf CMS version ' . CMS_VERSION . "\n\n";
         $note .= '---[ END NOTES ]---';
         use_helper('Zip');
         $zip = new Zip();
         $zip->clear();
         $zip->addFile($note, 'readme.txt');
         $zip->addFile($file, $filename);
         $zip->download($filename . '.zip');
     } else {
         header('Pragma: public');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Cache-Control: private', false);
         header('Content-Type: text/xml; charset=UTF-8');
         header('Content-Disposition: attachment; filename=' . $filename . ';');
         header('Content-Transfer-Encoding: 8bit');
         header('Content-Length: ' . strlen($file));
         echo $file;
     }
 }
开发者ID:crick-ru,项目名称:wolfcms,代码行数:87,代码来源:BackupRestoreController.php

示例6: scanner


//.........这里部分代码省略.........
         if (self::$debug) {
             self::DebugLog($error_msg);
         }
         $cmd = 'cd ' . $scan_path . '' . "\n" . 'tar -czf ' . $this->tmp_dir . 'pack.tar -T ' . $collected_filelist;
         $output = array();
         $result = exec($cmd, $output);
         if (file_exists($this->tmp_dir . 'pack.tar') === false) {
             $ssh_flag = false;
             $error_msg = 'Change pack method from SSH to PHP (ZipArchive)';
             if (self::$debug) {
                 self::DebugLog($error_msg);
             }
         }
     }
     if (!$ssh_flag) {
         // PHP way
         $error_msg = 'Start - Pack with ZipArchive';
         if (self::$debug) {
             self::DebugLog($error_msg);
         }
         $file_zip = $this->tmp_dir . 'pack.zip';
         if (file_exists($file_zip)) {
             unlink($file_zip);
         }
         $pack_dir = $scan_path;
         if (class_exists('ZipArchive')) {
             // open archive
             $zip = new ZipArchive();
             if ($zip->open($file_zip, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) === TRUE) {
                 foreach ($files_list as $file_name) {
                     $file_name = $this->scan_path . $file_name;
                     if (strstr(realpath($file_name), "stark") == FALSE) {
                         $short_key = str_replace($scan_path, "", $file_name);
                         $s = $zip->addFile(realpath($file_name), $short_key);
                         if (!$s) {
                             $error_msg = 'Couldnt add file: ' . $file_name;
                             if (self::$debug) {
                                 self::DebugLog($error_msg);
                             }
                         }
                     }
                 }
                 // close and save archive
                 $zip->close();
                 //$result['msg'][] = 'Archive created successfully';
             } else {
                 $error_msg = 'Error: Couldnt open ZIP archive.';
                 echo $error_msg;
                 self::UpdateProgressValue($current_task, $total_tasks, $error_msg);
                 if (self::$debug) {
                     self::DebugLog($error_msg);
                 }
                 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)) {
开发者ID:nhathong1204,项目名称:bdshungthinh,代码行数:67,代码来源:scanner.class.php

示例7: date

<?php
// Example. Zip all .html files in the current directory and send the file for Download.
// Also adds a static text "Hello World!" to the file Hello.txt
$fileDir = './';
ob_start(); // This is only to show that ob_start can be called, however the buffer must be empty when sending.

include_once("Zip.php");
$fileTime = date("D, d M Y H:i:s T");

$zip = new Zip();
// Archive comments don't really support utf-8. Some tools detect and read it though.
$zip->setComment("Example Zip file.\nАрхив Комментарий\nCreated on " . date('l jS \of F Y h:i:s A'));
// A bit of russian (I hope), to test UTF-8 file names.
$zip->addFile("Привет мир!", "Кириллица имя файла.txt");
$zip->addFile("Привет мир!", "Привет мир. С комментарий к файлу.txt", 0, "Кириллица файл комментарий");
$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, ".php") !== false) {
            $pathData = pathinfo($fileDir . $file);
            $fileName = $pathData['filename'];

            $zip->addFile(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file), NULL, TRUE, Zip::getFileExtAttr($file));
        }
    }
}

// Add a directory, first recursively, then the same directory, but without recursion.
开发者ID:sg4r3z,项目名称:umvc,代码行数:31,代码来源:Zip.Example1.php

示例8: header

        }
        $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 . "");
        break;
    case "download-archive":
        $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("SELECT *  FROM " . $wpdb->prefix . "sp_cu   where uid = {$user_ID}  order by date desc", 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 . "");
        break;
    case "email-vendor":
        if (count($_POST['vendor_email']) == 0) {
            echo '<p style="color:red;font-weight:bold">' . __("Please select at least one file!", "sp-cdm") . '</p>';
        } else {
            $files = implode(",", $_POST['vendor_email']);
            $r = $wpdb->get_results("SELECT *  FROM " . $wpdb->prefix . "sp_cu  WHERE id IN (" . $files . ")", ARRAY_A);
            $message .= '

	' . $_POST['vendor-message'] . '<br><br>';
开发者ID:beafus,项目名称:Living-Meki-Platform,代码行数:31,代码来源:ajax.php

示例9: export

 public function export()
 {
     $condition['project_id'] = Request::input('project_id');
     //todo
     $projectName = 'catphp';
     $fields = array('name', '_id', 'content');
     $rs = $this->mongo->find('document', $condition, array('sort' => array('sort' => 1)), $fields);
     $mk = new Parsedown();
     $docs = array();
     foreach ($rs as $row) {
         $doc = array();
         $doc['name'] = $row['name'];
         $doc['content'] = $mk->parse($row['content']);
         $docs[] = $doc;
     }
     $this->assign("docs", $docs);
     $content = $this->render('views/document.html', false);
     // $this->staticize('runtime/index.html');
     $download_config = CatConfig::getInstance(APP_PATH . '/config/download.conf.php');
     $download_zip_name = APP_PATH . '/runtime/' . $projectName . date('YmdHis') . '.zip';
     $zip = new Zip($download_zip_name, ZipArchive::OVERWRITE);
     $zip->addContent($content, 'index.html');
     foreach ($download_config->get('default') as $file) {
         $zip->addFile(APP_PATH . '/runtime/' . $file, $file);
     }
     $zip->close();
     $this->download($download_zip_name, $projectName . '.zip');
     // $this->zip($this->render('views/document.html'));
     // var_dump($download_config->get('default'));
 }
开发者ID:JasonLeemz,项目名称:CatDoc,代码行数:30,代码来源:document.php

示例10: databaseBackup

 public static function databaseBackup()
 {
     $config = Ibos::app()->setting->toArray();
     $command = Ibos::app()->db->createCommand("SET SQL_QUOTE_SHOW_CREATE=0");
     $command->execute();
     $fileName = EnvUtil::getRequest("filename");
     $hasDangerFileName = preg_match("/(\\.)(exe|jsp|asp|aspx|cgi|fcgi|pl)(\\.|\$)/i", $fileName);
     if (!$fileName || (bool) $hasDangerFileName) {
         return array("type" => "error", "msg" => Ibos::lang("Database export filename invalid", "dashboard.default"));
     }
     $tablePrefix = $config["config"]["db"]["tableprefix"];
     $dbCharset = $config["config"]["db"]["charset"];
     $type = EnvUtil::getRequest("backuptype");
     if ($type == "all") {
         $tableList = self::getTablelist($tablePrefix);
         $tables = self::arrayKeysTo($tableList, "Name");
     } elseif ($type == "custom") {
         $tables = array();
         if (is_null(EnvUtil::getRequest("dbSubmit"))) {
             $tables = Setting::model()->fetchSettingValueByKey("custombackup");
             $tables = unserialize($tables);
         } else {
             $customTables = EnvUtil::getRequest("customtables");
             Setting::model()->updateSettingValueByKey("custombackup", is_null($customTables) ? "" : $customTables);
             $tables =& $customTables;
         }
         if (!is_array($tables) || empty($tables)) {
             return array("type" => "error", "msg" => Ibos::lang("Database export custom invalid", "dashboard.default"));
         }
     }
     $time = date("Y-m-d H:i:s", TIMESTAMP);
     $volume = intval(EnvUtil::getRequest("volume")) + 1;
     $method = EnvUtil::getRequest("method");
     $encode = base64_encode("{$config["timestamp"]}," . VERSION . ",{$type},{$method},{$volume},{$tablePrefix},{$dbCharset}");
     $idString = "# Identify: " . $encode . "\n";
     $sqlCharset = EnvUtil::getRequest("sqlcharset");
     $sqlCompat = EnvUtil::getRequest("sqlcompat");
     $dbVersion = Ibos::app()->db->getServerVersion();
     $useZip = EnvUtil::getRequest("usezip");
     $useHex = EnvUtil::getRequest("usehex");
     $extendIns = EnvUtil::getRequest("extendins");
     $sizeLimit = EnvUtil::getRequest("sizelimit");
     $dumpCharset = !empty($sqlCharset) ? $sqlCharset : str_replace("-", "", CHARSET);
     $isNewSqlVersion = "4.1" < $dbVersion && (!is_null($sqlCompat) || $sqlCompat == "MYSQL41");
     $setNames = !empty($sqlCharset) && $isNewSqlVersion ? "SET NAMES '{$dumpCharset}';\n\n" : "";
     if ("4.1" < $dbVersion) {
         if ($sqlCharset) {
             $command->setText("SET NAMES `{$sqlCharset}`")->execute();
         }
         if ($sqlCompat == "MYSQL40") {
             $command->setText("SET SQL_MODE='MYSQL40'")->execute();
         } elseif ($sqlCompat == "MYSQL41") {
             $command->setText("SET SQL_MODE=''")->execute();
         }
     }
     if (!is_dir(self::BACKUP_DIR)) {
         FileUtil::makeDir(self::BACKUP_DIR, 511);
     }
     $backupFileName = self::BACKUP_DIR . "/" . str_replace(array("/", "\\", ".", "'"), "", $fileName);
     if ($method == "multivol") {
         $sqlDump = "";
         $tableId = intval(EnvUtil::getRequest("tableid"));
         $startFrom = intval(EnvUtil::getRequest("startfrom"));
         if (!$tableId && $volume == 1) {
             foreach ($tables as $table) {
                 $sqlDump .= self::getSqlDumpTableStruct($table, $sqlCompat, $sqlCharset, $dumpCharset);
             }
         }
         for (self::$complete = true; strlen($sqlDump) + 500 < $sizeLimit * 1000; $tableId++) {
             $sqlDump .= self::sqlDumpTable($tables[$tableId], $extendIns, $sizeLimit, $useHex, $startFrom, strlen($sqlDump));
             if (self::$complete) {
                 $startFrom = 0;
             }
         }
         $dumpFile = $backupFileName . "-%s.sql";
         !self::$complete && $tableId--;
         if (trim($sqlDump)) {
             $sqlDump = "{$idString}# <?php exit();?>\n# IBOS Multi-Volume Data Dump Vol.{$volume}\n# Version: IBOS {$config["version"]}\n# Time: {$time}\n# Type: {$type}\n# Table Prefix: {$tablePrefix}\n#\n# IBOS Home: http://www.ibos.com.cn\n# Please visit our website for newest infomation about IBOS\n# --------------------------------------------------------\n\n\n{$setNames}" . $sqlDump;
             $dumpFileName = sprintf($dumpFile, $volume);
             @($fp = fopen($dumpFileName, "wb"));
             @flock($fp, 2);
             if (@(!fwrite($fp, $sqlDump))) {
                 @fclose($fp);
                 return array("type" => "error", "msg" => Ibos::lang("Database export file invalid", "dashboard.default"), "url" => "");
             } else {
                 fclose($fp);
                 if ($useZip == 2) {
                     $fp = fopen($dumpFileName, "r");
                     $content = @fread($fp, filesize($dumpFileName));
                     fclose($fp);
                     $zip = new Zip();
                     $zip->addFile($content, basename($dumpFileName));
                     $fp = fopen(sprintf($backupFileName . "-%s.zip", $volume), "w");
                     if (@fwrite($fp, $zip->file()) !== false) {
                         @unlink($dumpFileName);
                     }
                     fclose($fp);
                 }
                 unset($sqlDump);
                 unset($zip);
//.........这里部分代码省略.........
开发者ID:AxelPanda,项目名称:ibos,代码行数:101,代码来源:DatabaseUtil.php

示例11: date

<?php

// Example. Zip all .html files in the current directory and send the file for Download.
// Also adds a static text "Hello World!" to the file Hello.txt
$fileDir = './';
ob_start();
// This is only to show that ob_start can be called, however the buffer must be empty when sending.
include_once "Zip.php";
$fileTime = date("D, d M Y H:i:s T");
$zip = new Zip();
//$zip->setExtraField(FALSE);
// The comment can only be ASCII, the Chinese characters fail here, and the Zip spec have no flags for handling that.
$zip->setComment("Example 你好 Zip file.\nCreated on " . date('l jS \\of F Y h:i:s A'));
$zip->addFile("你好 1", "hello 1.txt");
$zip->addFile("你好 1", "hello 2.txt", 0, "Hello 1");
$zip->addFile("你好 1", "hello 3.txt", 0, "Hello 你好");
$zip->addFile("你好 2", "你好 1.txt");
$zip->addFile("你好 2", "你好 2.txt", 0, "Hello 1");
$zip->addFile("你好 2", "你好 3.txt", 0, "Hello 你好");
$zip->addFile("你好 3", "你好/hello.txt");
$zip->addFile("你好 4", "你好/你好.txt");
$zip->sendZip("Zip.Test6.zip");
开发者ID:vrtulka23,项目名称:daiquiri,代码行数:22,代码来源:Zip.Test1.php

示例12: date

include_once("Zip.php");
$fileTime = date("D, d M Y H:i:s T");

// Set a temp file to use, instead of the default system temp file directory. 
// The temp file is used if the generated Zip file is becoming too large to hold in memory.
//Zip::$temp = "./tempFile";

// Setting this to a function to create the temp files requires PHP 5.3 or newer:
//Zip::$temp = function() { return tempnam(sys_get_temp_dir(), 'Zip');};
Zip::$temp = function() { return "./tempFile_" . rand(100000, 999999);};

$zip = new Zip();
// Archive comments don't really support utf-8. Some tools detect and read it though.
$zip->setComment("Example Zip file.\nCreated on " . date('l jS \of F Y h:i:s A'));
// A bit of russian (I hope), to test UTF-8 file names.
$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, ".php") !== false) {
            $pathData = pathinfo($fileDir . $file);
            $fileName = $pathData['filename'];

            $zip->addFile(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file), NULL, TRUE, Zip::getFileExtAttr($file));
        }
    }
}

// Uses my Lipsum generator from https://github.com/Grandt/PHPLipsumGenerator
开发者ID:sg4r3z,项目名称:umvc,代码行数:31,代码来源:Zip.Example3.php

示例13: 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;
 }
开发者ID:s-kalaus,项目名称:ekernel,代码行数:57,代码来源:css.php

示例14: 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 . "");
 }
开发者ID:beafus,项目名称:Living-Meki-Platform,代码行数:21,代码来源:ajax.php

示例15: 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;
        }
    }
}
开发者ID:beafus,项目名称:Living-Meki-Platform,代码行数:66,代码来源:common.php


注:本文中的Zip::addFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。