Reply
PHP Include and Directories Issue
Old 08-17-2007, 04:32 PM PHP Include and Directories Issue
Junior Talker

Posts: 4
Name: JC
Hello all,

Please help me with this. I know this is an easy one, but for some reason i can't figure it out.

I have created an include file in the following directory
Code:
root/includes/filename.php
and my code looks something like:
Code:
<?php include("includes/header.php");?>
my files were in the root directory, and the includes displayed fine. I have moved the files into another directory one level down
Code:
root/directory/filename.php
from the root. I'd like to continue to use the same include file (I don't want to have two separate "includes" directories for the same files)

Can anyone tell me how to get around this?

Last edited by pgwannabe : 08-17-2007 at 04:50 PM. Reason: clearer explanation
pgwannabe is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 08-17-2007, 04:34 PM Re: PHP Include and Directories Issue
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 386
Name: Jamie Lewis
Location: UK
You have moved the files...and you are wondering why that code isn't working? The files need to be in the same place relative to the includes. So if you move the include folder into the same folder as the main php code it should work.

Jamie
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 08-17-2007, 04:43 PM Re: PHP Include and Directories Issue
Junior Talker

Posts: 4
Name: JC
I understand that, but the thing is, I have a lot of files in my root directory calling the same include file. When I moved the files into the new directory, I just changed my css link from:
Code:
css/maincss.css
to
Code:
/css/maincss.css
and it worked fine. I was thinking I could do the same thing with the include files but obviously that's not the case.
pgwannabe is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 04:49 PM Re: PHP Include and Directories Issue
Extreme Talker

Posts: 182
'/' will take you back to root.

ex: include ( '/includes/file.php' ); will grab root/includes/file.php

'./' will take you back a directory i believe

ex: include ( './inlcudes/file.php' ); is probably what you want. Try that and let me know
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 04:51 PM Re: PHP Include and Directories Issue
Extreme Talker

Posts: 182
oops!
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 05:09 PM Re: PHP Include and Directories Issue
Ultra Talker

Posts: 250
I am not sure am I understand you, but maybe this script below can help you.

PHP Code:
<?php 
include_once $_SERVER['DOCUMENT_ROOT'] . "/somefolder/file.php"
?>
This script will always call your right file.php from any directory irrespective how deep is it.

Shivaji
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 08-17-2007, 05:16 PM Re: PHP Include and Directories Issue
Junior Talker

Posts: 4
Name: JC
Quote:
Originally Posted by bhgchris View Post
'/' will take you back to root.

ex: include ( '/includes/file.php' ); will grab root/includes/file.php

'./' will take you back a directory i believe

ex: include ( './inlcudes/file.php' ); is probably what you want. Try that and let me know
Perfect, that's all I needed. It actually worked when I used ('../includes/file.php') Thanks a lot for all of your help.
pgwannabe is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 05:25 PM Re: PHP Include and Directories Issue
tripy's Avatar
Fetchez la vache!

Posts: 2,171
Name: Thierry
Location: In the void
Quote:
'./' will take you back a directory i believe
Just for the record, this assumption is false.
./ means "in this directory"

../ means "up 1 directory"


the ./ is historically coming from unixes computers. The executable are not searched in the current directory, so to specify we want to run a program in the directory we are, ./myprogram must be typed.

This is still the case today in linux/bsd/osx in terminals
__________________
Listen to the ducky: "This is awesome!!!"


Last edited by tripy : 08-17-2007 at 05:27 PM.
tripy is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 06:04 PM Re: PHP Include and Directories Issue
Extreme Talker

Posts: 182
I realized that afterwards. Thanks for clarifying
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 02:30 AM Re: PHP Include and Directories Issue
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
Why not create a config file to simply the process
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Reply     « Reply to PHP Include and Directories Issue
 

Thread Tools

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

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


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15017 seconds with 12 queries