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


PHP FileHelper::packFiles方法代码示例

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


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

示例1: actionDownload_client

 public function actionDownload_client()
 {
     $afterDownload = false;
     if (isset($_POST['download'])) {
         $currentUser = Yii::app()->db->createCommand("SELECT * FROM external_users_usr WHERE id_usr=" . Yii::app()->user->userId)->queryRow();
         if ($currentUser['password_usr'] == ExternalUser::model()->passwordHash($_POST['password'])) {
             $afterDownload = true;
             $_SESSION['password'] = $_POST['password'];
         } else {
             Yii::app()->user->setFlash('_error', 'Wrong password!');
         }
     }
     if (isset($_GET['download'])) {
         $currentUser = Yii::app()->db->createCommand("SELECT * FROM external_users_usr WHERE id_usr=" . Yii::app()->user->userId)->queryRow();
         if ($currentUser['password_usr'] == ExternalUser::model()->passwordHash($_SESSION['password'])) {
             $password = $_SESSION['password'];
             $afterDownload = true;
             $tmpPath = VIREX_TEMP_PATH;
             $variables = array('START_DATE' => date('Y-m-d', strtotime('- 7 day')), 'END_DATE' => date('Y-m-d'), 'USERNAME' => $currentUser['name_usr'], 'PASSWORD' => $password, 'BASE_URL' => VIREX_URL);
             // step 1. Create username dir
             if (file_exists($tmpPath . '/' . $currentUser['name_usr'])) {
                 if (file_exists($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.inc')) {
                     unlink($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.inc');
                 }
                 if (file_exists($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.php')) {
                     unlink($tmpPath . '/' . $currentUser['name_usr'] . '/sampleshare.php');
                 }
             } else {
                 mkdir($tmpPath . '/' . $currentUser['name_usr']);
             }
             $tmpPath = $tmpPath . '/' . $currentUser['name_usr'] . '/';
             // step 2. copy originaly files
             copy(VIREX_APP_PATH . '/protected/sampleshareclient/sampleshare.inc', $tmpPath . 'sampleshare.inc');
             copy(VIREX_APP_PATH . '/protected/sampleshareclient/sampleshare.php', $tmpPath . 'sampleshare.php');
             // step 3. replace variables
             $original = file_get_contents($tmpPath . 'sampleshare.php');
             foreach ($variables as $k => $v) {
                 $original = str_replace('<!--' . $k . '--!>', $v, $original);
             }
             file_put_contents($tmpPath . 'sampleshare.php', $original);
             // step 4. create zip archive
             $files = array($tmpPath . 'sampleshare.inc', $tmpPath . 'sampleshare.php');
             FileHelper::packFiles($files, $tmpPath, 'zip.zip');
             // step 5. download contents
             header('Content-Type: application/octet-stream');
             header('Content-Disposition: attachment; filename="norman-sampleshare-client-example.zip"');
             header('Content-Transfer-Encoding: binary');
             readfile($tmpPath . 'zip.zip');
             // step 6. clean folder
             unlink($tmpPath . 'sampleshare.inc');
             unlink($tmpPath . 'sampleshare.php');
             unlink($tmpPath . 'zip.zip');
             rmdir($tmpPath);
             unset($_SESSION['password']);
         } else {
             Yii::app()->user->setFlash('_error', 'Wrong password!');
         }
     }
     $this->render('download_client', array('afterDownload' => $afterDownload));
 }
开发者ID:vman747,项目名称:virex,代码行数:60,代码来源:SiteController.php


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