0
カスタムメイドのwordpress
プラグインの機能を作成しようとしています。ユーザーがダウンロードボタンをクリックすると、そのポストに関連するディレクトリから適切なファイルをダウンロードする必要があります。wordpressプラグインのカスタムダウンロード機能
URLからファイルに直接アクセスできないようにするには、ユーザーにファイルのダウンロードを許可する必要があります。私はhref
タグにリンクを置いたり、直接URLからそれをアクセスした場合
class DownloadM{
function __construct(){
}
function setDownload($file){
//$file = ROOT_DIR_PATH."wp-content/uploads/2016/07/PDF.zip";
echo "<a href='".$file."'>Click here to download</a>";
ob_start();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=PDF.zip");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
flush();
ob_clean();
readfile($file);
}
}
ファイルが正常にダウンロードされてきています。
しかし、私はautoにヘッダにファイルを置いたときにダウンロードし、それはあなたのために