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 var,它没问题("../chat/1.2/messages.txt");

文件也在那里。我还尝试了从 C 开始的路径:

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

但没有成功。你能帮帮我吗?

解决方案

readFile() 和 $this->readFile() 是不同的函数。代码没问题,但从未被调用。感谢您的回复。

4

1 回答 1

1

Your function is defined as private:

private function readFile($fileName)

Code outside of that class won't have access to directly call private functions inside it.

于 2014-06-24T22:09:08.497 回答