お世話になります。
PHP初心者のものです。
サーバ上にあるcsvファイルをダウンロードしようと
したところ、中身が
サーバ上にあるcsvデータの中身は正しいままです。
php
1// ファイルのパス 2$filepath = 'test.csv'; 3// リネーム後のファイル名 4$filename = 'テスト.csv'; 5 6header('Content-Disposition: attachment; filename="'.$filename.'"'); 7header('Content-Type: application/octet-stream'); 8header('Content-Transfer-Encoding: binary'); 9header('Content-Length: '.filesize($filepath)); 10 11readfile($filepath);
[追記]
以下の方法でやると、HTML文が全文出た後に出力予定のcsvファイルの中身が
出力されました。
php
1// ファイルのパス 2$filepath = 'test.csv'; 3// リネーム後のファイル名 4$filename = 'テスト.csv'; 5 6header('Content-Description: File Transfer'); 7header("Content-Disposition: attachment; filename=$filename"); 8header('Content-Type: application/force-download;'); 9 10readfile($filepath);
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/08 06:18
退会済みユーザー
2016/07/08 06:21 編集
2016/07/08 06:46