簡體   English   中英

PHP-fopen:無法打開流:權限被拒絕

[英]PHP - fopen: failed to open stream: Permission denied

我是PHP新手。 我計划根據用戶輸入將文件夾創建為子文件夾。

文件夾和子文件夾已成功創建。

最后,我嘗試創建一個文件,顯示波紋管錯誤。

fopen(upload / localhost / hrms):無法打開流:205行的C:\\ xampp \\ htdocs \\ ssspider \\ index.php中的權限被拒絕

我的代碼是:

$dir = "http://localhost:8080/hrms/index.php";

//make directory
$directoryForServer = "upload";
$directoryForClient = $directoryForServer."/".$host."";
mkdir($directoryForClient);


$splitePath = explode("/", $folderPath);

$folderPath1 = $directoryForClient;

for($x = 1; $x <= (count($splitePath)-1) ; $x++)
{
    $folderPath1 = $folderPath1."/".$splitePath[$x];
    echo "<br>".$folderPath1." - successfully created<br>";
    mkdir($folderPath1);
}

writefile($folderPath1);



function writefile($dir)
{
 if( is_dir($dir)){
    echo $dir;

    $myFile = fopen($dir,"w");
    if($myFile)
    {
        fwrite($myFile, $returned_content);
    }
    fclose($myFile);
  }
}

請幫我找出問題所在嗎?

編輯:謝謝。 我有一個錯誤。 在fopen中,我沒有提到文件名。 現在它的工作正常。 謝謝

因為打開目錄,所以fopen函數只打開文件。 您的代碼充滿了錯誤,只需參考以下內容:

<?php  

//make directory
$host = "aa";         //define $host variable
$directoryForServer = "upload";
$directoryForClient = $directoryForServer."/".$host."";
@mkdir($directoryForClient);  

$splitePath = explode("/", $directoryForClient);
$folderPath1 = $directoryForClient;

for($x = 1; $x <= (count($splitePath)-1) ; $x++)
{
    $folderPath1 = $folderPath1."/".$splitePath[$x];
    echo "<br>".$folderPath1." - successfully created<br>2";
    @mkdir($folderPath1);
}

writefile($folderPath1);


function writefile($dir)
{
 if( is_dir($dir)){
    echo $dir;
    $myFile = fopen("upload/aa.txt","w");
    if($myFile)
    {
        $returned_content = "hello world";  //define variable and his content before write to file.
        fwrite($myFile, $returned_content);
    }
    fclose($myFile);
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM