PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
gautamz07
Forum Contributor
Posts: 331 Joined: Wed May 14, 2014 12:18 pm
Post
by gautamz07 » Tue Nov 11, 2014 1:21 am
i understand require and include :
what this though :
Code: Select all
require_once realpath(dirname(__FILE__) . '/../../autoload.php');
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Tue Nov 11, 2014 1:44 am
dirname
realpath
Together they look for autoload.php by starting in the same location as the current file, going to its directory, and going up two more directories.
gautamz07
Forum Contributor
Posts: 331 Joined: Wed May 14, 2014 12:18 pm
Post
by gautamz07 » Tue Nov 11, 2014 3:20 am
Thank you .
gautamz07
Forum Contributor
Posts: 331 Joined: Wed May 14, 2014 12:18 pm
Post
by gautamz07 » Tue Nov 11, 2014 7:23 am
i have the following diractory structure :
Code: Select all
filepath
- include.php
ONE
- index.php
this works inindex.php :
Code: Select all
<?php
require_once realpath(dirname(__FILE__) . '../../include.php');
echo "i am echo";
?>
now include.php is just one directory up , so i don't really understand why i have to do two paths ../../ upwards.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Tue Nov 11, 2014 7:40 am
You shouldn't need to. You also shouldn't mix dirname and ../
Does this not work?
Code: Select all
include realpath(dirname(dirname(__FILE__))) . '/include.php';