PHPにて、リンクをクリックしたら、ファイルを自動的にダウンロードするphpを実行するという方法ならよく出てくるのですが、そうではなくて、とある処理の途中でファイルダウンロードのphpを実行するというのをやりたいと考えています。しかしその方法がわかりません。
php
1// main.php 2require(plugin_dir_path( __FILE__ )."download.php");
php
1// download.php //ダウンロードの指示 2header('Content-Type:application/octet-stream'); 3header('Content-Disposition:filename=download.txt'); 4header('Content-Length:' . filesize('download.txt')); 5readfile("download.txt"); 6} 7return "ok";
requireでダウンロード用の外部PHP呼び出しをしてみましたが、「Warning: Cannot modify header information - headers already sent by ~」というエラーになってできませんでした。
php
1// main.php 2exec($fullpath . "download.php > /dev/null &", $output, $status); 3var_dump($output); 4var_dump($status); 5}
また、execというのも使ってみたのですが、$outputはempty、$statusは0になって、何もない同然の結果になってしまいました。
手動でphpへのリンクをクリックさせる以外に、ファイルダウンロードを自動的に行う方法はないのでしょうか?
回答1件
あなたの回答
tips
プレビュー