PHPを使用したファイルダウンロードコードがあり、ダウンロードページのコードは次のとおりです。
if (file_exists($strDownload)) {
//get the file content
$strFile = file_get_contents($strDownload);
//set the headers to force a download
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"" . str_replace(" ", "_", $arrCheck['file_name']) . "\"");
//echo the file to the user
echo $strFile;
//update the DB to say this file has been downloaded
mysql_query("xxxxxxxx");
exit;
}
関数file_exists()
が有効なチェックで渡された場所と私の変数は、サーバーフォルダーにある$strDownload
ようなものになります。/home/public_html/uploads/myfile.zip
しかし、ファイルをダウンロードする代わりにダウンロードしようとすると、ページにはファイルの完全に暗号化されたソースが表示されます。ダウンロードできるようにするにはどうすればよいですか?
編集:情報については、私はワードプレスシステム内でこのコードを使用しようとしていますが、私のファイルパスはhttp://example.com/wp-content/uploads/2016/02/myfile.zip
. また、上記のコードfile_exists()
では、すでに上で述べたサーバーパスの条件を自分でチェックし、1
必要に応じて返します。