Jump to content

Archived

This topic is now archived and is closed to further replies.

marek

Fopen

Recommended Posts

I want to open txt file which is in the same folder that php file.
How can I use fopen function to open this txt file if I don't want to give specific path to this txt file?
thanks
marek

Share this post


Link to post
Share on other sites
Try:
$file = './sometextfile.txt';
if ($open = fopen($file, 'r'))
{
do stuff
}

The 'r' is for read, 'w' is for write and 'x' is for both I believe, check out the specifics at php.net/fopen

Share this post


Link to post
Share on other sites
Great. It works. Thanks.
So how to use the same fopen function if txt file is in folder which is "in higher level" (for example there's folder 'folder1' which includes 'file1.txt' and 'folder2'; and folder2 includes 'file1.php')?
I still don't want to give specifc path to the txt file.
marek

Share this post


Link to post
Share on other sites
Ok really quickly this is how directories in unix work...

./ = current directory
../ = the directory above you
./somedirectory/file.php = get file.php in the directory somedirectory which is in the same directory as you
../somedirecotry/file.phhp = get file.php in the directory somedirectory which is in the directory above yours

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.