2017-06-02 61 views
0

我制作了文件管理器应用程序 我尝试下载文件时遇到问题 上传目录中的文件和从我的PHP临时目录中移动不继承该文件夹的权限,所以我就在PHP错误日志此错误readfile():无法打开流:在Windows Server IIS 8上拒绝访问

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"); 
    } 
+0

检查权限 –

+2

['无法打开流:权限被拒绝'错误 - Laravel](https://stackoverflow.com/q/23540083/6521116) –

+0

您是否将权限更改为该目录? –

回答

0

嗯,如果你可以ch ange文件夹权限,可以解决问题。也许你还需要重新启动IIS。

那么,你正在使用ob_clean,当你丢弃输出缓冲区的内容。无论如何,如果您在调用函数之前使用ob_clean内容,则可能会出现该错误。那么......有可能你在其他php文件中留下了一些空间或其他“隐形”字符?

+0

我重新启动了IIS,我已经检查了所有文件夹的权限但没有运气。我也给了我的临时文件夹相同的权限 – Bill

+0

尝试传递完整的文件路径,如“c:/ foo/bar”而不是相对路径 – sensorario

+0

如果php作为服务安装,则需要重新启动php。 – sensorario

相关问题