本文整理匯總了PHP中FileHelper::outputFile方法的典型用法代碼示例。如果您正苦於以下問題:PHP FileHelper::outputFile方法的具體用法?PHP FileHelper::outputFile怎麽用?PHP FileHelper::outputFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FileHelper
的用法示例。
在下文中一共展示了FileHelper::outputFile方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionDownload
public function actionDownload($name, $id)
{
if ($name !== null) {
$userFilePath = Yii::getPathOfAlias('site.files') . '/workshops/' . $id;
$userFilePath .= "/" . $name;
if (!FileHelper::outputFile($name, $userFilePath)) {
throw new CHttpException(404, 'File not found');
}
}
}
示例2: actionDownloadPortfolioZip
public function actionDownloadPortfolioZip()
{
if (isset($_POST) && isset($_POST['stu_job_id']) && !empty($_POST['stu_job_id'])) {
$criteria = new CDbCriteria();
$criteria->addInCondition('stu_job_id', $_POST['stu_job_id']);
$criteria->select = 'stu_job_id,student_id,stu_job_id,first_name,last_name,portfolio_file';
$selectedJobs = ViewStudentJobTitle::model()->findAll($criteria);
if ($selectedJobs != null) {
$tmpZipFile = tempnam(sys_get_temp_dir(), 'zip');
//FileHelper::getFilePath(Yii::getPathOfAlias('site.files').'/resumes/temp/zip/',true);
$zip = new ZipArchive();
if ($zip->open($tmpZipFile, ZipArchive::OVERWRITE) === true) {
foreach ($selectedJobs as $key => $job) {
$student_id = $job['student_id'];
$stu_job_id = $job['stu_job_id'];
$first_name = $job['first_name'];
$last_name = $job['last_name'];
$name = $job['portfolio_file'];
if (empty($name)) {
continue;
}
$ext = CFileHelper::getExtension($name);
$userFilezipName = $first_name . $last_name . '_pf_jobtitle_' . $stu_job_id . '.' . $ext;
if ($name !== null) {
$userFilePath = Yii::getPathOfAlias('site.files') . '/resumes/' . $student_id;
$userFilePath .= '/' . $name;
if (file_exists($userFilePath)) {
$zip->addFile($userFilePath, $userFilezipName);
}
}
}
if ($zip->close()) {
if (!FileHelper::outputFile('portfoliosZip' . Randomness::randomString() . '.zip', $tmpZipFile)) {
throw new CHttpException(404, 'Download zip failed');
}
}
}
}
die;
} else {
throw new CHttpException(400, "Unable to find the selected filesll");
}
}