日本語名指定でファイルをダウンロードする画面がありますが、
IEとEdgeのみファイル名が文字化けするので下記を参考に修正しましたがダウンロード出来なくなってしまいました。
どこに原因があるのでしょうか?
また、原因を特定するためのデバッグ方法等がありましたらご教授下さい。
元々参考にした方法:
CakePHP CakeResponseを使ったファイルのダウンロード
http://qiita.com/madiehak/items/9b104be97c4c37a3465d
参考した対策法:
CakePHP2の $this->response でファイルをダウンロードさせるときのIEファイル名文字化け解消
http://qiita.com/aion/items/e10f23f76bca7d1f4fb2
View/Hogehoge/index.ctp
javascript
1$scope.clickb = function() { 2 $('#iframe_id')[0].contentDocument.location.replace('/Hogehoge/download_ajax'); 3}
Controller/HogehogeController
php
1function download_ajax(){ 2 $this->download('hogehoge.docx'); 3} 4function download($file_name = null) { 5 // viewを使用しない 6 $this->autoRender = false; 7 8 // ファイルがcake/app/webroot/files以下にあるとき 9 // WWW_ROOT, DS は定数 公式サイト参照 10 $file_path = WWW_ROOT.'application'.DS.$file_name; 11 12 // [削除]response->file()でダウンロードもしくは表示するファイルをセット 13 //$this->response->file($file_path); 14 // [削除]pdfをブラウザ上で開かせるような場合はこちら 15 //$this->response->body($file_name); 16 // [削除]ファイル名指定 17 //$this->response->download('ほげほげ.txt'); //これだとIE/Edgeで文字化けする 18 19 // [追加]-> 20 $file = $this->Attachment->getFile($file_path); 21 $filename = 'ほげほげ.txt'; 22 $content = 'attachment;'; 23 $content .= 'filename='.$filename; 24 $content .= 'filename*=UTF-8\'\''.rawurlencode($filename); 25 $this->response->header('Content-Disposition', $content); 26 $this->response->file($file['path']); 27 28 // レスポンスオブジェクトを返すとコントローラがビューの描画を中止します 29 return $this->response; 30 // <-[追加] 31}
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/07 10:09
退会済みユーザー
2016/12/07 10:12