2013年10月15日火曜日

[cakephp] ファイルをダウンロードする

file_get_contentsを使う場合
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);
cakephp 1.3 MediaView を使う場合
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);
cakephp 2.X MediaView を使う場合 viewがviewClassとなる しかし2.3で撤廃となっているので2.4以降は次のCakeResponse::downloadを使う
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);
cakephp 2.4 以降であれば
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');

2013年10月1日火曜日

[iOS] iAdのサイズ

iAdのサイズ
iPhoneが縦向きの時は 320×50 points
iPhoneが横向きの時は 480×32 points
iPadが縦向きの時は 768×66 points
iPadが横向きの時は 1024×66 points

[cakephp] PaginatorHelper::conter()の$options['format']の和訳

以下の文をapp/locale/jpn/LC_MESSAGES/default.poに記述する 1.3の場合
1
2
msgid "Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%"
msgstr "全 %pages% 頁中 %page% 頁目 全 %count% 件中 %start% 件~ %end% 件まで %current% 件を表示"
2.xの場合
1
2
msgid "Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}"
msgstr "全 {:pages} 頁中 {:page} 頁目 全 {:count} 件中 {:start} 件~ {:end} 件まで {:current} 件を表示"