File not found exception inside php class
Hello and thanks for your time. I have a problem with the following code:
//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;
}
I have this function in a class, but every time i call fopen it throws the
following exception:
Warning: readfile(messages.txt): failed to open stream: No such file or
directory in C:\xampp\htdocs\zdupp\php\textChat.php on line 85
But I checked the $location var and it is ok("../chat/1.2/messages.txt");
Also the file is there. I also tried a path starting from C:
C:/xampp/htdocs/zdupp/chat/1.2/messages.txt
But with no success. Could you please help me out?
No comments:
Post a Comment