【发布时间】:2015-08-23 05:50:16
【问题描述】:
我是一名新的 PHP 程序员。我正在尝试编写代码以允许用户从我的网站下载文本文件。我遵循了有关该主题的类似问题的答案,并整理了以下测试程序。它没有强制下载到文件,而是将内容发送到屏幕(在 Chrome、IE、Firefox 中)。有人能指出我做错了什么吗?
这是我的测试代码:
<?php
$file = "test.txt";
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
$type = filetype($file);
// Send file headers
header("Content-type: $type");
header("Content-Disposition: attachment;filename=\"test.txt\"");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
// Send the file contents.
set_time_limit(0);
readfile($file);
exit();
?>
【问题讨论】:
-
测试代码没有出现。我会再试一次:
-
-
您的问题下方有一个“编辑”链接。您可以单击它并将缺少的代码添加到问题中,而不是添加评论。