本文整理汇总了PHP中Eccube\Application::sendFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::sendFile方法的具体用法?PHP Application::sendFile怎么用?PHP Application::sendFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Eccube\Application
的用法示例。
在下文中一共展示了Application::sendFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download
/**
* テンプレート一覧からのダウンロード
*
* @param Application $app
* @param Request $request
* @param $id
*/
public function download(Application $app, Request $request, $id)
{
/** @var $Template \Eccube\Entity\Template */
$Template = $app['eccube.repository.template']->find($id);
if (!$Template) {
throw new NotFoundHttpException();
}
// 該当テンプレートのディレクトリ
$config = $app['config'];
$templateCode = $Template->getCode();
$targetRealDir = $config['root_dir'] . '/app/template/' . $templateCode;
$targetHtmlRealDir = $config['root_dir'] . '/html/template/' . $templateCode;
// 一時ディレクトリ
$uniqId = sha1(Str::random(32));
$tmpDir = $config['template_temp_realdir'] . '/' . $uniqId;
$appDir = $tmpDir . '/app';
$htmlDir = $tmpDir . '/html';
// ファイル名
$tarFile = $config['template_temp_realdir'] . '/' . $uniqId . '.tar';
$tarGzFile = $tarFile . '.gz';
$downloadFileName = $Template->getCode() . '.tar.gz';
// 該当テンプレートを一時ディレクトリへコピーする.
$fs = new Filesystem();
$fs->mkdir(array($appDir, $htmlDir));
$fs->mirror($targetRealDir, $appDir);
$fs->mirror($targetHtmlRealDir, $htmlDir);
// tar.gzファイルに圧縮する.
$phar = new \PharData($tarFile);
$phar->buildFromDirectory($tmpDir);
// appディレクトリがない場合は, 空ディレクトリを追加
// @see https://github.com/EC-CUBE/ec-cube/issues/742
if (empty($phar['app'])) {
$phar->addEmptyDir('app');
}
$phar->compress(\Phar::GZ);
// ダウンロード完了後にファイルを削除する.
// http://stackoverflow.com/questions/15238897/removing-file-after-delivering-response-with-silex-symfony
$app->finish(function (Request $request, Response $response, \Silex\Application $app) use($tmpDir, $tarFile, $tarGzFile) {
$app['monolog']->addDebug('remove temp file: ' . $tmpDir);
$app['monolog']->addDebug('remove temp file: ' . $tarFile);
$app['monolog']->addDebug('remove temp file: ' . $tarGzFile);
$fs = new Filesystem();
$fs->remove($tmpDir);
$fs->remove($tarFile);
$fs->remove($tarGzFile);
});
return $app->sendFile($tarGzFile)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $downloadFileName);
}
示例2: download
public function download(Application $app, Request $request)
{
if ($file = $request->get('select_file')) {
if (!is_dir($file)) {
$pathParts = pathinfo($file);
$patterns = array('/[a-zA-Z0-9!"#$%&()=~^|@`:*;+{}]/', '/[- ,.<>?_[\\]\\/\\\\]/', "/['\r\n\t\v\f]/");
$str = preg_replace($patterns, '', $pathParts['basename']);
if (strlen($str) === 0) {
return $app->sendFile($file)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
} else {
return $app->sendFile($file)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, ord($pathParts['basename']));
}
}
}
return;
}
示例3: download
public function download(Application $app, Request $request)
{
$topDir = $app['config']['user_data_realdir'];
$file = $this->convertStrToServer($request->get('select_file'));
if ($this->checkDir($file, $topDir)) {
if (!is_dir($file)) {
$filename = $this->convertStrFromServer($file);
setlocale(LC_ALL, 'ja_JP.UTF-8');
$pathParts = pathinfo($file);
$patterns = array('/[a-zA-Z0-9!"#$%&()=~^|@`:*;+{}]/', '/[- ,.<>?_[\\]\\/\\\\]/', "/['\r\n\t\v\f]/");
$str = preg_replace($patterns, '', $pathParts['basename']);
if (strlen($str) === 0) {
return $app->sendFile($file)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
} else {
return $app->sendFile($file, 200, array("Content-Type" => "aplication/octet-stream;", "Content-Disposition" => "attachment; filename*=UTF-8\\'\\'" . rawurlencode($this->convertStrFromServer($pathParts['basename']))));
}
}
}
throw new NotFoundHttpException();
}
示例4: download
public function download(Application $app, Request $request)
{
$topDir = $app['config']['user_data_realdir'];
$file = $request->get('select_file');
if ($this->checkDir($file, $topDir)) {
if (!is_dir($file)) {
$pathParts = pathinfo($file);
$patterns = array('/[a-zA-Z0-9!"#$%&()=~^|@`:*;+{}]/', '/[- ,.<>?_[\\]\\/\\\\]/', "/['\r\n\t\v\f]/");
$str = preg_replace($patterns, '', $pathParts['basename']);
if (strlen($str) === 0) {
return $app->sendFile($file)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
} else {
return $app->sendFile($file)->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, ord($pathParts['basename']));
}
}
}
throw new NotFoundHttpException();
}