すでにダウンロードリンクがあると言ったのを見てください。ファイルにリンクするだけです。
<a href="download.php?file=user-cv.pdf">Download</a>
そして、で、このようdownload.php
に与えContent-disposition: attachment;
ます:
<?php
# Sanitize the code to avoid injection
$file = "uploads/" . stripslashes(str_replace(array("..", "/"), "", $_GET["file"]));
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-type: application/pdf');
readfile($file);
die();
?>
警告:
コービンが言ったように、人々がファイルに直接アクセスしようとすると、大きなセキュリティホールがあります。次の方法でアクセスできるように、ファイル名、ファイルタイプとしてDBに保存することをお勧めします。
<a href="download.php?user=praveenscience">Download</a>
そして、PHPコードで、MySQLサーバーから結果を取得し、次のようにダウンロードします。
<?php
$file = mysql_result(/* Query Here */);
header('Content-Disposition: attachment; filename="' . $file["filename"] . '"');
header('Content-type: ' . $file["mimetype"]);
readfile($file["filename"]);
die();
?>