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