我已经制作了一个文件管理器应用程序当我尝试下载文件时,我有问题上传目录中的文件并已从我的php Temp目录移动的文件不继承文件夹权限,因此我在PHP错误日志中遇到了此错误
PHP Warning: readfile(files/xxx.zip): failed to open stream: Permission denied in ...
当我进入IIS并进入"安全性"选项卡并应用继承权限时,它可以正常工作
<?php
set_time_limit(0);
ini_set('memory_limit', '2147483648');
$file = "files/".htmlspecialchars($_GET["file"]);
$quoted = sprintf('"%s"',addcslashes(basename($file),'"\"'));
$size = filesize($file);
if (file_exists($file)) {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: force-download");
header("Content-Disposition: attachment; filename=".$quoted);
header("Content-Transfer-Encoding: binary");
header('Connection: Keep-Alive');
header("Content-Length: ".$size);
ob_clean();
flush();
readfile($file);
} else {
header("Location: fileNotFound.php?file=$file");
}
mmm如果您可以更改文件夹权限,则可以解决问题。也许您还需要重新启动IIS。
好吧,您正在使用丢弃输出缓冲区内容时可用的ob_clean
。无论如何,如果您在调用该功能之前使用ob_clean
内容,则可以获得该错误。所以,...您可能在其他PHP文件中溜走了一些"空间或其他"无形"字符?