コード例 #1
0
 /**
  * テンプレート一覧からのダウンロード
  *
  * @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
0
 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
0
ファイル: FileController.php プロジェクト: hiroyasu55/ec-cube
 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
0
 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();
 }