Page 1 of 1

understanding a new kind of include .

Posted: Tue Nov 11, 2014 1:21 am
by gautamz07
i understand require and include :

what this though :

Code: Select all

require_once realpath(dirname(__FILE__) . '/../../autoload.php');

Re: understanding a new kind of include .

Posted: Tue Nov 11, 2014 1:44 am
by requinix
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.

Re: understanding a new kind of include .

Posted: Tue Nov 11, 2014 3:20 am
by gautamz07
Thank you . :)

Re: understanding a new kind of include .

Posted: Tue Nov 11, 2014 7:23 am
by gautamz07
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.

Re: understanding a new kind of include .

Posted: Tue Nov 11, 2014 7:40 am
by Celauran
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';

Re: understanding a new kind of include .

Posted: Fri Nov 14, 2014 3:20 am
by gautamz07
Thanks