Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 4
Name: JC
Trades: 0
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 03:50 PM.. Reason: clearer explanation
pgwannabe is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-17-2007, 03:34 PM Re: PHP Include and Directories Issue
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 385
Name: Jamie Lewis
Location: UK
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 08-17-2007, 03:43 PM Re: PHP Include and Directories Issue
Junior Talker

Posts: 4
Name: JC
Trades: 0
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, 03:49 PM Re: PHP Include and Directories Issue
Extreme Talker

Posts: 182
Trades: 0
'/' 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, 03:51 PM Re: PHP Include and Directories Issue
Extreme Talker

Posts: 182
Trades: 0
oops!
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-17-2007, 04:09 PM Re: PHP Include and Directories Issue
shivaji's Avatar
Ultra Talker

Posts: 321
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
- uncommon free scripts

Please login or register to view this content. Registration is FREE
- Städte, Sport, Party, Gourment, Apartments, Hotels
shivaji is offline
Reply With Quote
View Public Profile Visit shivaji's homepage!
 
Old 08-17-2007, 04:16 PM Re: PHP Include and Directories Issue
Junior Talker

Posts: 4
Name: JC
Trades: 0
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, 04:25 PM Re: PHP Include and Directories Issue
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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
__________________
Only a biker knows why a dog sticks his head out the window.

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

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

Posts: 730
Name: John
Location: United States of America, California
Trades: 0
Why not create a config file to simply the process
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Reply     « Reply to PHP Include and Directories Issue
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





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



Page generated in 0.30191 seconds with 12 queries