Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get link path if i want include another folder

Tags:

php

I want to know that how can i give include path of another folder.

For example, i have a project named test folder. In test folder has one folder which is assets folder and index.php file. In assets folder has two folder which are include and xyz folder. In include folder has two file which are header.php and footer.php.In header.php file has three link home, product and customer. In xyz folder has product.php and customer.php file.

In index.php, product.php and customer.php i want to include header.php and footer.php.

But i can't right path.

<?php include('../../header.php');?>

...........

<?php include('../../footer.php');?>

Please help me, how can i give right path which if i click product link then header.php and footer.php will be load.


2 Answers

Try this :

<?php
include_once(dirname(__FILE__) . '/database.class.php');
?>

Ref: http://php.net/manual/en/function.dirname.php

like image 182
Prasanth Bendra Avatar answered Jan 24 '26 10:01

Prasanth Bendra


If your Directory look something like this:

src
->includes
  ->header.php
  ->footer.php
web
->index.php

And you want to include the header and the footer in the index.php, do the following:

<?php
   //index.php
   include __DIR__.'/../src/includes/header.php';
   echo "foobar";
   include __DIR__.'/../src/includes/footer.php';
?>

http://php.net/manual/en/language.constants.predefined.php

like image 34
c4pone Avatar answered Jan 24 '26 11:01

c4pone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!