我已将.pdf,.doc,.txt文件存储在Web服务器的目录中。我能够显示目录内存储的所有文件,但下载失败。每次我点击超链接sample.txt获取与空白内容下载。请查看代码并提出建议。
这是我在show_directory.php中使用的
// Define the full path to your folder from root
$path = "/public_html/bc/upload/";
// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
// Loop through the files
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "download_file.php" )
continue;
echo "$file
";
}
// Close
closedir($dir_handle);
?>download_file.php的内容是:
//download.php
//content type
header('Content-type: text/plain');
//open/save dialog box
header('Content-Disposition: attachment; filename="sample.txt"');
//read from server and write to buffer
readfile('test.txt');
?>