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


Php, files get bigger with full path name?

使用下面的小下载脚本:

$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)

if(file_exists($file) && is_readable($file))