Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 22nd Sep 2014, 02:39 AM   #1
Highly Compressed pc Game
 
Join Date: 2014
Posts: 38
Thanks: 13
Thanked 2 Times in 2 Posts
Default
php include help need
Share on: 
fb share twitter share gplus share more share

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..

Muhammad sakil is offline  
Unread 22nd Sep 2014, 10:30 AM   #2
VIP Warrior
War Room Member
 
Join Date: 2006
Location: , , USA.
Posts: 1,795
Thanks: 70
Thanked 287 Times in 259 Posts
Default
Re: php include help need
Share on: 
fb share twitter share gplus share more share

did you try it?
everything you typed could work.
KirkMcD is offline  
Unread 22nd Sep 2014, 01:30 PM   #3
Conceited Know-It-All
 
kilgore's Avatar
 
Join Date: 2014
Location: Amurrica
Posts: 952
Thanks: 465
Thanked 1,136 Times in 503 Posts
Default
Re: php include help need
Share on: 
fb share twitter share gplus share more share

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:
<?php include '../post/mypost.php';?>
(Note the ".." before the "/" above)

Alternatively you could do something like:
PHP Code:
<?php include '/path/to/DocumentRoot/post/mypost.php';?>

kilgore is offline  
Unread 24th Sep 2014, 11:40 AM   #4
Active Warrior
 
Join Date: 2014
Location: Toronto, Canada
Posts: 33
Thanks: 0
Thanked 1 Time in 1 Post
Default
Re: php include help need
Share on: 
fb share twitter share gplus share more share

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

Mr Alexander

Web Developer & Consultant with extensive experience, since 1998

Websites.Consulting
mralexanderca is offline  
Unread 29th Sep 2014, 09:41 PM   #5
HyperActive Warrior
 
Member8200's Avatar
 
Join Date: 2008
Posts: 310
Thanks: 10
Thanked 39 Times in 35 Posts
Default
Re: php include help need
Share on: 
fb share twitter share gplus share more share

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.
Member8200 is offline  
Closed Thread


Bookmarks

Tags
files, include, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 06:46 AM.