Re: [PHP] Problem with file reading
- From: stuttle@xxxxxxxxx (Stut)
- Date: Fri, 05 Jan 2007 17:40:49 +0000
Roman Neuhauser wrote:
# stuttle@xxxxxxxxx / 2007-01-05 17:17:46 +0000:
Roman Neuhauser wrote:
# stuttle@xxxxxxxxx / 2007-01-05 16:34:41 +0000:The OP referred to the "servers root folder". Now stop nit-picking and go back to quoting standards.
Delta Storm wrote:Arent' you confusing this with something else? fopen() is affected
I'm a beginner and i'm still learning PHP and I got a problem:Is there a reason why you're trying to access it through a URL? If not, please don't.
$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!");
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".
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.
by the current working directory of the process calling it. What kind of
"root" are you talking about? The filesystem root, "/"?
I'm not nitpicking. If the webserver process (assuming mod_php) runs in
a different directory, fopen("relative/to/documentroot/path.txt") won't
help him at all, and as far as I can tell, it's quite common for web
servers to run with pretty much any cwd, often / or /var/empty (these
are local filesystem paths).
Ok, let me clarify...
Using mod_php with Apache will make the current directory the directory that contains the script being requested. I am assuming that the OP is trying to access the file from the script that is being requested and not an included file in a different directory - I should have been clearer on that.
I never said anything about being relative to the document root - you pulled that out of somewhere yourself.
Happy now?
-Stut
.
- Follow-Ups:
- Re: [PHP] Problem with file reading
- From: Roman Neuhauser
- Re: [PHP] Problem with file reading
- References:
- Problem with file reading
- From: Delta Storm
- Re: [PHP] Problem with file reading
- From: Stut
- Re: [PHP] Problem with file reading
- From: Roman Neuhauser
- Re: [PHP] Problem with file reading
- From: Stut
- Re: [PHP] Problem with file reading
- From: Roman Neuhauser
- Problem with file reading
- Prev by Date: Re: [PHP] Problem with file reading
- Next by Date: Re: How is it that PHP source scripts can be downloaded via HTTP?
- Previous by thread: Re: [PHP] Problem with file reading
- Next by thread: Re: [PHP] Problem with file reading
- Index(es):
Relevant Pages
|
|