Jump to content


Photo

Fopen


  • Please log in to reply
4 replies to this topic

#1 marek

marek
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 28 June 2006 - 08:33 PM

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

#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 28 June 2006 - 08:34 PM

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
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 marek

marek
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 28 June 2006 - 08:48 PM

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

#4 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 28 June 2006 - 08:52 PM

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
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#5 marek

marek
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 28 June 2006 - 09:28 PM

It also works. Thanks a lot.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users