2008年7月1日 星期二

如何用 php 寫出下載檔案功能

$path = "../tv2.exe"; //路徑及下載的檔案
$name = "tv3.exe"; //下載後的檔名
if (!file_exists($path))
echo "錯誤";
else {
header("Content-type: application/download");
header("Content-Disposition: attachment; filename=$name");
header("Content-Transfer-Encoding: binary");
readfile($path);
}
?>

$path 還可以跨過 /var/www/html 到上一層:/var/www