Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.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
Php,使用完整路径名的文件会变大吗?_Php_Download - Fatal编程技术网

Php,使用完整路径名的文件会变大吗?

Php,使用完整路径名的文件会变大吗?,php,download,Php,Download,使用一个小的下载脚本,内容如下: $file = "$tempDir/download.zip"; if($file) { header("Content-Disposition: attachment; filename=" . basename($file)); header("Content-Type: application/zip"); readfile($file); } 当这个php脚本放在下载源旁边,并且只使用“download.zip”时,它就可以正常

使用一个小的下载脚本,内容如下:

$file = "$tempDir/download.zip";
if($file) {
    header("Content-Disposition: attachment; filename=" . basename($file));
    header("Content-Type: application/zip");
    readfile($file);
}
当这个php脚本放在下载源旁边,并且只使用“download.zip”时,它就可以正常工作了
但除此之外,我会得到一些同名的垃圾文件,它是10KB,而不是代码中预期的1KB。$file总是==true

最好换个新的

if($file)


确保文件正常。

下载的“垃圾”文件可能包含PHP错误,这对发现解决方案非常有用。如果您尝试使用文本编辑器打开它,它可能会帮助您找出问题所在:-)
if(file_exists($file) && is_readable($file))