本文整理汇总了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));
}