2017-06-02 39 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

相關問題