public function download($id = null, $file = null) {
		$type = $this->_controller->RequestHandler->prefers();
		$exportFileName = null;
		if (method_exists($this->_model, 'getExportFilename')) {
			$exportFileName = $this->_model->getExportFilename($id, true);
		}

		$exportPath = $this->_getExportDir();
		$downloadFile = $exportPath . $file;
		if (!empty($type)) {
			$downloadFile .= '.' . $type;
		}

		if (!file_exists($downloadFile)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid file for downloading'));
		}

		if (!empty($type) && !empty($exportFileName)) {
			$this->_controller->response->type($type);
			$exportFileName .= '.' . $type;
		}
		$responseOpt = [
			'download' => true,
		];
		if (!empty($exportFileName)) {
			if ($this->_controller->request->is('msie')) {
				$exportFileName = rawurlencode($exportFileName);
			}
			$responseOpt['name'] = $exportFileName;
		}
		$this->_controller->response->file($downloadFile, $responseOpt);

		return $this->_controller->response;
	}
public function download($id = null, $file = null) {
		$type = $this->_controller->RequestHandler->prefers();
		$exportFileName = null;
		if (method_exists($this->_model, 'getExportFilename')) {
			$exportFileName = $this->_model->getExportFilename($id, true);
		}

		$exportPath = $this->_getExportDir();
		$downloadFile = $exportPath . $file;
		if (!empty($type)) {
			$downloadFile .= '.' . $type;
		}

		if (!file_exists($downloadFile)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid file for downloading'));
		}

		if (!empty($type) && !empty($exportFileName)) {
			$this->_controller->response->type($type);
			$exportFileName .= '.' . $type;
		}
		$responseOpt = [
			'download' => true,
		];
		if (!empty($exportFileName)) {
			if ($this->_controller->request->is('msie')) {
				$exportFileName = rawurlencode($exportFileName);
			}
			$responseOpt['name'] = $exportFileName;
		}
		$this->_controller->response->file($downloadFile, $responseOpt);

		return $this->_controller->response;
	}
public function download ( $ id = null , $ file = null ) { $ type = $ this -> _controller -> RequestHandler -> prefers ( ) ; $ exportFileName = null ; if ( method_exists ( $ this -> _model , 'getExportFilename' ) ) { $ exportFileName = $ this -> _model -> getExportFilename ( $ id , true ) ; } $ exportPath = $ this -> _getExportDir ( ) ; $ downloadFile = $ exportPath . $ file ; if ( ! empty ( $ type ) ) { $ downloadFile .= '.' . $ type ; } if ( ! file_exists ( $ downloadFile ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid file for downloading' ) ) ; } if ( ! empty ( $ type ) && ! empty ( $ exportFileName ) ) { $ this -> _controller -> response -> type ( $ type ) ; $ exportFileName .= '.' . $ type ; } $ responseOpt = [ 'download' => true , ] ; if ( ! empty ( $ exportFileName ) ) { if ( $ this -> _controller -> request -> is ( 'msie' ) ) { $ exportFileName = rawurlencode ( $ exportFileName ) ; } $ responseOpt [ 'name' ] = $ exportFileName ; } $ this -> _controller -> response -> file ( $ downloadFile , $ responseOpt ) ; return $ this -> _controller -> response ; }
Downloading preview file

@param int|string $id ID for downloaded data.
@param string $file File name of downloaded file.
@throws InternalErrorException if downloaded is not exists.
@return CakeRequest Return CakeRequest object for download request.
Downloading preview file