1 2 3 4 5 6 | Configure::write( 'debug' , 0); // デバッグをOFFに $this ->autoRender = false; // オートレンダーをOFFに $this ->header( 'Content-Type: application/octet-stream' ); $this ->header( 'Content-Length: ' . filesize ( $filepath )); $this ->header( 'Content-disposition: attachment; filename="' . $filename . '"' ); echo file_get_contents ( $filepath ); |
1 2 3 4 5 6 7 8 9 10 | Configure::write( 'debug' , 0); // デバッグをOFFに $this ->view = 'Media' ; $params = array ( 'id' => 'example.zip' , 'name' => 'example' , 'extension' => 'zip' , 'download' => true, 'path' => APP . 'outside_webroot_dir' . DS , // APP/webroot からの相対パスもしくはフルパス ); $this ->set( $params ); |
1 2 3 4 5 6 7 8 9 10 | Configure::write( 'debug' , 0); // デバッグをOFFに $this ->viewClass = 'Media' ; $params = array ( 'id' => 'example.zip' , 'name' => 'example' , 'extension' => 'zip' , 'download' => true, 'path' => 'files' . DS , // APP/webroot からの相対パスもしくはフルパス ); $this ->set( $params ); |
1 2 3 4 | Configure::write( 'debug' , 0); // デバッグをOFFに $this ->autoRender = false; // オートレンダーをOFFに $this ->response->file( 'files/example.zip' ); // APP/webroot からの相対パスもしくはフルパス $this ->response->download( 'example.zip' ); |