protected function _deliverMedia(CakeResponse $response, $mediaFile, $mediaInfo) { $response->sharable(true, 2592000); //$response->mustRevalidate(true); $response->expires('+30 days'); $modTime = filemtime($mediaFile); $response->modified($modTime); $response->etag(md5($mediaFile . $modTime)); //$response->header("Pragma", "cache"); $response->type($mediaInfo['ext']); $response->file($mediaFile); $response->send(); }
/** * testFileNotFound * * @expectedException NotFoundException * @return void */ public function testFileNotFound() { $response = new CakeResponse(); $response->file('/some/missing/folder/file.jpg'); }
/** * test file with .. * * @expectedException NotFoundException * @return void */ public function testFileWithPathTraversal() { $response = new CakeResponse(); $response->file('my/../cat.gif'); }
/** * Although unlikely, a file may contain dots in its filename. * This should be allowed, as long as the dots doesn't specify a path (../ or ..\) * * @expectedException NotFoundException * @execptedExceptionMessageRegExp #The requested file .+my/Some..cat.gif was not found or not readable# * @return void */ public function testFileWithDotsInFilename() { $response = new CakeResponse(); $response->file('my/Some..cat.gif'); }
/** * ダウンロード * * @param string $filename ダウンロード時のファイル名 * @return CakeResponse */ public function download($filename) { $response = new CakeResponse(); $response->type('text/csv'); $response->file($this->path, ['name' => $filename, 'download' => 'true']); return $response; }
/** * Download * * @param string $filename download時のファイル名 * @return CakeResponse ダウンロードレスポンス */ public function download($filename) { // closeされてなかったらcloseする if ($this->_open) { $this->close(); } $response = new CakeResponse(); $response->type('application/zip'); $response->file($this->path, ['name' => $filename, 'download' => 'true']); return $response; }