Home > Backend Development > PHP Tutorial > 设计了一个php下载目前文件,却把php源文件下载下来了,为何

设计了一个php下载目前文件,却把php源文件下载下来了,为何

WBOY
Release: 2016-06-13 12:45:30
Original
1001 people have browsed it

设计了一个php下载当前文件,却把php源文件下载下来了,为何?
当我点a.txt下载后,打开txt文件,发现里面的内容不是a.txt本身的内容,而是该php文件中除了php代码的其他文本内容,这样该如何解决?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><br />
<title>资料下载</title><br />
</head><br />
<br />
<body><br />
<?php <br />
$file_name="a.txt";<br />
$file_dir="./";<br />
if(!file_exists($file_dir.$file_name)){<br />
 echo "文件找不到";  <br />
 exit;<br />
}else{<br />
$file=fopen($file_dir.$file_name,"r");//打开文件<br />
	echo($file_dir.$file_name);<br />
 Header("Content-type: application/octet-stream");  <br />
 Header("Accept-Ranges:bytes");  <br />
 Header("Accept-Length:".filesize($file_dir.$file_name));  <br />
 Header("Content-Disposition: attachment; filename=".$file_name);<br />
 }<br />
<br />
?><br />
<br />
</body><br />
</html><br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template