note 19692 added to function.fopen
| From: | artist at canvasdreams dot com | Date: | Thu, 07 Mar 2002 19:57:37 +0000 |
| Subject: | note 19692 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27489@lists.php.net to get a copy of this message | ||
This is a followup answer to php@opilki.com [from 28-Jan-2002]. I too was having problems writing
files to my web site by referencing them with paths like "/home/httpd/html/blah/blah.txt".
The documentation I'd read in this manual was very confusing, and it seemed to indicate I
should reference a file path from the home directory.
Here's the solution I found:
When using fopen() on a local file [a file on the same server or directory structure as the script
calling the fopen() function], the path used in referencing that file should reflect a relative
path. So if the file calling fopen() is located at:
[root]/scripts/static.php
and the file you want to access is:
[root]/files/misc/article.txt
then the fopen() function, in the static.php script, should read as follows:
fopen("../files/misc/article.txt","w")
This will relative-reference the file, and you can then read it, write to it, whatever. In other
words, it's the same as when using <img src="relative path"> in an HTML
document, to reference an image file located on the same web site. This answer seems obvious enough,
but the PHP manual doesn't explicitly state it anywhere.
To summarize, fopen() works well with absolute URLs [http://...] and relative paths [../path/...].
--
http://www.php.net/manual/en/function.fopen.php
http://master.php.net/manage/user-notes.php?action=edit+19692
http://master.php.net/manage/user-notes.php?action=delete+19692
http://master.php.net/manage/user-notes.php?action=reject+19692