470,815 Members | 1,312 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Referencing a File or Folder

I'm trying to point to an include file from php like so:

<?php require('/main/includes/nav_stripe.php');?>

That approach is perfectly fine when trying to point to a folder
INCLUDES inside folder MAIN on the root IN HTML. However, php is
producing errors.

Is there a solid safe way to reference a file/folder regardless of how
many levels up or down it is?

May 8 '06 #1
4 1521
bbs
Do Google search
Check User Contributed Notes in http://tw2.php.net/require

-=-=-=-=-
http://www.livibetter.com

May 8 '06 #2
TristaSD wrote:
I'm trying to point to an include file from php like so:

<?php require('/main/includes/nav_stripe.php');?>

That approach is perfectly fine when trying to point to a folder
INCLUDES inside folder MAIN on the root IN HTML. However, php is
producing errors.

Is there a solid safe way to reference a file/folder regardless of how
many levels up or down it is?


When you use absolute filenames, PHP references it to the OS's file system root,
not the root directory of your website. So unless you have a file on your
computer called

/main/includes/nav_stripe.php

this will fail.

If you want to be relative to your website's root directory, you need to use:

<?php require($_SERVER['DOCUMENT_ROOT'] . '/main/includes/nav_stripe.php'); ?>

or something similar.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 8 '06 #3
TristaSD wrote:
I'm trying to point to an include file from php like so:

<?php require('/main/includes/nav_stripe.php');?>

That approach is perfectly fine when trying to point to a folder
INCLUDES inside folder MAIN on the root IN HTML. However, php is
producing errors.

Is there a solid safe way to reference a file/folder regardless of how
many levels up or down it is?

Set the include_path configuration directive to an absolute path (where
you then keep your include files) and then all you need do is include
the filename (with no path).

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
The world is my country,
Science, my religion.
*****************************
May 8 '06 #4
Chuck Anderson wrote:
TristaSD wrote:
I'm trying to point to an include file from php like so:

<?php require('/main/includes/nav_stripe.php');?>

That approach is perfectly fine when trying to point to a folder
INCLUDES inside folder MAIN on the root IN HTML. However, php is
producing errors.

Is there a solid safe way to reference a file/folder regardless of how
many levels up or down it is?


Set the include_path configuration directive to an absolute path (where
you then keep your include files) and then all you need do is include
the filename (with no path).


That's great if you have access to the configuration. Most shared hosts don't
allow it. And doing it in .htaccess is less efficient.

This works with any Apache host and doesn't require .htaccess.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Macka | last post: by
2 posts views Thread by Chang | last post: by
5 posts views Thread by David C | last post: by
4 posts views Thread by steve_barker333 | last post: by
1 post views Thread by Dave Anson | last post: by
1 post views Thread by Henry Stock | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.