Re: Problem with file reading

From: Date: Fri, 05 Jan 2007 17:17:46 +0000
Subject: Re: Problem with file reading
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-246615@lists.php.net to get a copy of this message
Roman Neuhauser wrote:
# stuttle@gmail.com / 2007-01-05 16:34:41 +0000:
Delta Storm wrote:
    
I'm a beginner and i'm still learning PHP and I got a problem: $file = "http://localhost/test_folder/test1.txt"; //I have also tried "test_folder/test1.txt" and "text1.txt" $fh = fopen($file, "r") or die("Could not open file!"); $data = fread($fh, filesize($file)) or die ("Could not read file!"); fclose($fh); echo $data;
The file exist, I'm using apache server on my PC for practicing and the file is located in the servers root folder on the subfolder "test_folder".
      
Is there a reason why you're trying to access it through a URL? If not, please don't. The file path needs to be relative to the current file. So if your PHP file is in the root, "test_folder/test1.txt" should work. If your PHP file is in a folder named code in the root, "../test_folder/text1.txt" should work.
    
Arent' you confusing this with something else? fopen() is affected by the current working directory of the process calling it. What kind of "root" are you talking about? The filesystem root, "/"? The OP referred to the "servers root folder". Now stop nit-picking and go back to quoting standards. -Stut

« previous php.general (#246615) next »