Account Login
 User Name Password Remember Me?
 Latest Articles
 by awuehr on 11-10-2008 in Tips & Tricks by Village Idiot on 11-04-2008 in Classes & Objects by codefreek on 10-23-2008 in Basic by wiifanatic on 09-12-2008 in Security & Permissions by drewbee on 07-03-2008 in Tips & Tricks
 IRC Channel
 Join the friendly bunch on IRC... (#TalkPHP on Freenode) ...Also available via a web interface. See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
 Associates
 Associates
 TalkPHP » includes and reading txt file
 LinkBack Thread Tools Search this Thread Display Modes
 07-07-2010, 01:24 PM #1 (permalink) The Contributor     Join Date: Feb 2010 Posts: 69 Thanks: 16 includes and reading txt file Just a little thing im doing to get my experience up. Im trying many different things and i would like to know how to go about this little thing im trying Iv got index.php in the main directory - uses include/head.php iv got head.php which is in the includes directory - this reads a text file which is in a location going from main directory Admin/Docs/head.txt There is nothing wrong with this it reads the file exactly how i want it. However iv got now in the admin directory index.php which also includes ../includes/head.php So the problem i have got is its not seeing it correctly because of the directory location when it reads the head.php the text file location is incorrect reading it as Admin/docs/head.txt and because it is already in the admin location from the admin/index.php it pulls out a file does not exist. How would i go about fixing this. Thanks
 07-07-2010, 06:40 PM #2 (permalink) Moderateur          Join Date: Apr 2007 Posts: 1,393 Thanks: 5 The best way to make sure the right path is used, is to provide an absolute one. Commonly that means using something like __DIR__ (or dirname(__FILE__) if you're not blessed with being able to use PHP 5.3 yet) to get the absolute path to the file the constant is written in. For example, inside your head.php file: PHP Code:  include __DIR__ . '/../Admin/Docs/head.txt';   If the path to head.php was /home/path/to/site/includes/head.php then __DIR__ would be /home/path/to/site/includes. That would make the included file be located at /home/path/to/site/includes/../Admin/Docs/head.txt which is just the same as /home/path/to/site/Admin/Docs/head.txt. With that, you would continue including the head.php as you are and the path would always be correct for the head.txt file.
 The Following User Says Thank You to Salathe For This Useful Post:
 Tim Dobson (07-08-2010)
07-08-2010, 10:43 PM   #3 (permalink)
The Contributor

Join Date: Feb 2010
Posts: 69
Thanks: 16

Quote:
 Originally Posted by Salathe The best way to make sure the right path is used, is to provide an absolute one. Commonly that means using something like __DIR__ (or dirname(__FILE__) if you're not blessed with being able to use PHP 5.3 yet) to get the absolute path to the file the constant is written in. For example, inside your head.php file: PHP Code:  include __DIR__ . '/../Admin/Docs/head.txt';   If the path to head.php was /home/path/to/site/includes/head.php then __DIR__ would be /home/path/to/site/includes. That would make the included file be located at /home/path/to/site/includes/../Admin/Docs/head.txt which is just the same as /home/path/to/site/Admin/Docs/head.txt. With that, you would continue including the head.php as you are and the path would always be correct for the head.txt file.
ok i think i am with you but i failed to get that to work so i thought i would try something like

PHP Code:
 <?php                      $myFile = "E:\domain\link\sb0t.tentun.co.uk\goin\to\the\file\head.txt";$fh = fopen($myFile, 'r');$theData = fread($fh, filesize($myFile)); fclose($fh); echo '' .$theData . ''; ?> 
Which correct me if i am wrong would do vertualy the same thing?

It is getting the absolute path and then printing out the data from the file. Atleast it seems to work for me doing it such a way.

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On

 Similar Threads Thread Thread Starter Forum Replies Last Post [Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM PHP/MySQL tips and tricks jaswinder_rana Tips & Tricks 6 07-17-2005 01:56 AM

All times are GMT. The time now is 01:51 PM.

 Contact Us - TalkPHP - PHP Community - Archive - Top

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design