| | #1 |
| Highly Compressed pc Game Join Date: 2014
Posts: 38
Thanks: 13
Thanked 2 Times in 2 Posts
|
hey any one know ho to add many diffrent files from diffrent folders in a single php file.. this code works only for same folder where footer.php place <?php include 'footer.php';?> i want to add different files from diffrent folder like <?php include 'head.php';?> <?php include '/post/mypost.php';?> <?php include '/comment/comment.php';?> <?php include 'footer.php';?> so please help me.. |
| | |
| |
| | #2 |
| VIP Warrior War Room Member Join Date: 2006 Location: , , USA.
Posts: 1,795
Thanks: 70
Thanked 287 Times in 259 Posts
|
did you try it? everything you typed could work. |
| |
| | #3 |
| Conceited Know-It-All Join Date: 2014 Location: Amurrica
Posts: 952
Thanks: 465
Thanked 1,136 Times in 503 Posts
|
Check your paths. When you put a "/" in your include statement you're saying to include a file relative to the root of the server, not the document root of your website. Probably what you're looking for is something like: PHP Code: Alternatively you could do something like: PHP Code: |
| | |
| |
| | #4 |
| Active Warrior Join Date: 2014 Location: Toronto, Canada
Posts: 33
Thanks: 0
Thanked 1 Time in 1 Post
|
What I would recommend is first setting up a file "paths.php" that will have few constants defined to the needed paths, for example: // path to the root folder define('DIR_ROOT',dirname(__FILE__) . '/'); // path to the config folder define('DIR_CONFING', DIR_ROOT . 'config'); etc. include DIR_ROOT . 'footer.php'; include DIR_ROOT . 'head.php'; You would then include it at the top of your script and include the files as needed, this is very prone to movement of the script and you will not have to change your constants often, even if you do, you would simply do so one. Hope this helps. Mr Alexander |
| | |
| |
| | #5 |
| HyperActive Warrior Join Date: 2008
Posts: 310
Thanks: 10
Thanked 39 Times in 35 Posts
|
there's no issue on adding a single '/' before a folder name, and everything you type should work. please re-check your folder paths. I also suggest you use require rather than include require statement will produce a (E_COMPILE_ERROR) and stop the script include statement will only produce a warning (E_WARNING) and the script will continue 'include' could give you more errors because the page will continue to execute even if the file you include is missing and that could affect the next line of codes 'require' will stop the page for further execution. |
| |
|
| Bookmarks |
| Tags |
| files, include, php |
| Thread Tools | Search this Thread |
| |