Exemplo n.º 1
0
 /**
  * 動画のzipダウンロード
  *
  * @return CakeResponse
  * @throws NotFoundException 表示できない記事へのアクセス
  * @throws ForbiddenException アクセス権なし
  * @see DownloadComponent::doDownload()
  */
 public function download()
 {
     // ダウンロードリンク使わないなら、400
     if (!$this->useDownloadLink) {
         return $this->setAction('throwBadRequest');
     }
     // ブロック編集許可(編集長以上)持っていないなら403
     if (!Current::permission('block_editable')) {
         throw new ForbiddenException();
     }
     // ここから元コンテンツを取得する処理
     //$this->_prepare();
     $key = $this->params['key'];
     $conditions = $this->Video->getConditions();
     $conditions['Video.key'] = $key;
     $query = array('conditions' => $conditions);
     $video = $this->Video->find('first', $query);
     // ここまで元コンテンツを取得する処理
     // ダウンロード実行
     if (!$video) {
         // 表示できない記事へのアクセスなら404
         throw new NotFoundException(__d('videos', 'Invalid video entry'));
     }
     // 圧縮用パスワードキーを求める
     if (!empty($this->request->data['AuthorizationKey']['authorization_key'])) {
         $zipPassword = $this->request->data['AuthorizationKey']['authorization_key'];
     } else {
         $this->_setFlashMessageAndRedirect($key, __d('authorization_keys', 'please input compression password'));
         return;
     }
     // ダウンロードファイル名はタイトルにする
     $fileName = $video['Video']['title'];
     $zipFileName = $fileName . '.zip';
     $videoFileName = $fileName . '.mp4';
     $realFilePath = APP . WEBROOT_DIR . DS . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['path'] . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['id'] . DS . $video['UploadFile'][Video::VIDEO_FILE_FIELD]['real_file_name'];
     $zip = new ZipDownloader();
     $zip->addFile($realFilePath, $videoFileName);
     $zip->setPassword($zipPassword);
     $zip->close();
     return $zip->download($zipFileName);
 }
Exemplo n.º 2
0
 /**
  * zip download
  *
  * @param string $zipFilename Zipファイル名
  * @param string $csvFilename ZipされるCsvファイル名
  * @param string|null $password Zipにつけるパスワード
  * @return CakeResponse
  */
 public function zipDownload($zipFilename, $csvFilename, $password = null)
 {
     // csvファイルを$csvFilenameへリネーム
     $this->_rename($csvFilename);
     // zipFile作成
     $zip = new ZipDownloader();
     $zip->addFile($this->path);
     // zipのダウンロードを実行
     if (strlen($password)) {
         $zip->setPassword($password);
     }
     $zip->close();
     return $zip->download($zipFilename);
 }