1

こんにちは、お時間をいただきありがとうございます。次のコードに問題があります。

//reads all the data from $fileName and returns it
private function readFile($fileName)
{
    $location = $this->path.$fileName;
    try{//try to open file
        $file=fopen($location,"r");
    }
    catch(Exception $e){
        return $e;
    }

    $return = "";//read file contents
    while (!feof($file))
    {
        $return .= fgetc($file);
    }

    //close file and return result
    fclose($file);

    return $return;
}

クラスにこの関数がありますが、fopen を呼び出すたびに次の例外がスローされます。

Warning: readfile(messages.txt): failed to open stream: No such file or directory in C:\xampp\htdocs\zdupp\php\textChat.php on line 85

しかし、 $location 変数を確認したところ、問題ありませんでした("../chat/1.2/messages.txt");

ファイルもあります。Cから始まるパスも試しました:

C:/xampp/htdocs/zdupp/chat/1.2/messages.txt

しかし、成功しませんでした。助けていただけませんか?

解決

readFile() と $this->readFile() は別の関数でした。コードは問題ありませんでしたが、呼び出されませんでした。返信ありがとうございます。

4

1 に答える 1

1

あなたの関数は次のように定義されていprivateます:

private function readFile($fileName)

そのクラス外のコードは、そのprivateクラス内の関数を直接呼び出すことができません。

于 2014-06-24T22:09:08.497 に答える