我正在使用PHP来处理文件下载。目前,如果文件不可用,我只会显示一条信息。 (如果旧文件版本从外部网站链接,会出现)PHP - 重定向到下载页面,如果文件不可用
如何直接重定向到下载页面? (例如www.example.com/downloads.html)
if (!is_file($file_path)) {
die("<center><strong><u>file not available</u><strong></center>");
}
我正在使用PHP来处理文件下载。目前,如果文件不可用,我只会显示一条信息。 (如果旧文件版本从外部网站链接,会出现)PHP - 重定向到下载页面,如果文件不可用
如何直接重定向到下载页面? (例如www.example.com/downloads.html)
if (!is_file($file_path)) {
die("<center><strong><u>file not available</u><strong></center>");
}
使用PHP头是你需要重定向什么。不过,请确保您事先没有任何回应,标题必须首先出现在回复中。
header('Location: http://www.example.com/downloads.html');
如果需要,您也可以在这里使用相对URL。
而且如下面的评论中所述,您需要http://
协议,否则它会被视为相对网址。
尝试PHP头功能重定向
http://sg2.php.net/manual/en/function.header.php
header('Location: www.example.com/downloads.html');
你也需要标题中的'Location:'部分。即'header('Location:www.example.com/downloads.html');'你也可以使用相关的URL。 – 2012-07-14 15:20:17
错误地更新了它。感谢 – venkat 2012-07-14 15:39:25
使用协议(http://),否则它将被视为相对url – 2012-07-14 15:29:03