Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
下载.zip文件问题(下载.php文件)_Php_File_Download_Zip - Fatal编程技术网

下载.zip文件问题(下载.php文件)

下载.zip文件问题(下载.php文件),php,file,download,zip,Php,File,Download,Zip,我想下载一个.zip文件,但当我去下载它时,它迫使我下载.php文件。我使用的这个简单的代码遍布互联网,所以我不知道为什么我不能下载.zip文件 header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header("Content-type:

我想下载一个.zip文件,但当我去下载它时,它迫使我下载.php文件。我使用的这个简单的代码遍布互联网,所以我不知道为什么我不能下载.zip文件

header("Cache-Control: no-store, no-cache, must-revalidate");  
header("Cache-Control: post-check=0, pre-check=0", false);  
header("Pragma: no-cache");  
header("Content-type: application/zip");  
header('Content-length: '.filesize($fullpath));  
header("Content-disposition: attachment; filename=".basename($fullpath));  

readfile($fullpath);  

如果您正在使用扩展名为.zip的PHP文件提供服务,那么获取下载的PHP源代码是预期的行为-默认情况下,PHP解释器不会解析zip文件

您必须注册要由PHP解析的ZIP扩展名。不过,这是相当次优的;在本例中,您可以链接到扩展名为.PHP的PHP文件。
filename
标题将为下载文件的用户提供正确的名称


如果您使用的是.php扩展名,并且提供了php文件的源代码,则表明您的服务器配置已中断。

我认为您正在下载名为
.php

的zip文件
尝试使用
winzip
winrar

打开下载的文件,您使用的是哪个浏览器?您确定您不仅仅下载名为.php的zip文件吗?您不需要
filesize($fullfile)
?我在readfile()中使用了完整路径,现在改变了,你的代码现在对我来说很好。你把readfile和include混淆了。readfile不会像include那样尝试解释该文件。它只是“读取一个文件并将其写入输出缓冲区。”@Gerben在向下投票之前读取注释。整个PHP源代码都会被下载,而且从一开始就不会被解释。可能是因为他使用的是.zip扩展名而不是.phpsorry,所以误读了@phpEnthusiast wat是php代码的文件名?