2016-08-09 7 views
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にヘッダにファイルを置いたときにダウンロードし、それはあなたのために

答えて

0

簡単な解決策は機能しません。

header("Content-Type: application/force-download"); 
関連する問題