marek Posted June 28, 2006 Share Posted June 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13150-fopen/ Share on other sites More sharing options...
Buyocat Posted June 28, 2006 Share Posted June 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13150-fopen/#findComment-50578 Share on other sites More sharing options...
marek Posted June 28, 2006 Author Share Posted June 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13150-fopen/#findComment-50584 Share on other sites More sharing options...
Buyocat Posted June 28, 2006 Share Posted June 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13150-fopen/#findComment-50587 Share on other sites More sharing options...
marek Posted June 28, 2006 Author Share Posted June 28, 2006 It also works. Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/13150-fopen/#findComment-50596 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.