understanding a new kind of include .

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

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

understanding a new kind of include .

Post by gautamz07 »

i understand require and include :

what this though :

Code: Select all

require_once realpath(dirname(__FILE__) . '/../../autoload.php');
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: understanding a new kind of include .

Post 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.
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: understanding a new kind of include .

Post by gautamz07 »

Thank you . :)
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: understanding a new kind of include .

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: understanding a new kind of include .

Post 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';
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: understanding a new kind of include .

Post by gautamz07 »

Thanks
Post Reply