471,319 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

including files - paths

If I'm working on a project, I'll usually create a folder to contain all
the project files before uploading this to the root of the production
server. The trouble is that if I do:
include('/myfile.php')
this looks at the root of local host, as it should and not at the root
of the working directory. It means that if I want to use absolute
links, I have to change them before I upload.

Or am I missing something blindingly obvious?

I'm pretty sure this has been done before (FAQ entry material?), but not
for a while. :-)
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
Jul 17 '05 #1
3 1301
Geoff Berrow wrote:
If I'm working on a project, I'll usually create a folder to contain
all the project files before uploading this to the root of the
production server. The trouble is that if I do:
include('/myfile.php') this looks at the root of local host, as it
should and not at the root of the working directory. It means that
if I want to use absolute links, I have to change them before I
upload.
Change or extend your local configuration so that it reflects the
configuration at the remote server.

An easy way is creating a virtual host on your local box with a
documentroot pointing to the wannabe /...
Or am I missing something blindingly obvious?

No, I don't think so

Hans

--
"He who asks a question is a fool for five minutes;
he who does not ask a question remains a fool forever"
Jul 17 '05 #2
I noticed that Message-ID: <42*********************@news.xs4all.nl> from
Hans van Kranenburg contained the following:
Change or extend your local configuration so that it reflects the
configuration at the remote server.

An easy way is creating a virtual host on your local box with a
documentroot pointing to the wannabe /...


Any idea where I might find instructions on how to do that?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
Geoff Berrow wrote:
If I'm working on a project, I'll usually create a folder to contain all the project files before uploading this to the root of the production
server. The trouble is that if I do:
include('/myfile.php')
this looks at the root of local host, as it should and not at the root of the working directory. It means that if I want to use absolute
links, I have to change them before I upload.
The quick solution is to use relative path (something like
.../foo.php or ./foo.php). But, if we use relative path for all
includes, it will hit performance. So, I use something like:

<?php
//config.inc.php
$CFG['project_path'] = '/home/foo/foo/';
//etc etc
?>

<?php
//foo.php
require_once('../common/config.inc.php'); //relative to project
require_once($CFG['project_path'] . 'html/header.html'); //absolute
//etc etc...
require_once($CFG['project_path'] . 'html/footer.html'); //absolute
?>

As seen, only one path is relative. I even have a mechanism to auto
detect the project path in config.inc.php.
I'm pretty sure this has been done before (FAQ entry material?), but not for a while. :-)


Yes, this has to be included in FAQ. But, what could be an
appropriate question?

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by jordan | last post: by
2 posts views Thread by shruti | last post: by
1 post views Thread by shruti | last post: by
1 post views Thread by Martin Mücke | last post: by
12 posts views Thread by duzhidian | last post: by
3 posts views Thread by Alexander Vasilevsky | last post: by
10 posts views Thread by kimiraikkonen | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.