Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 860
  • Last Modified:

Working with PHP Absolute Path differences between production server and MAMP development server

I'm running MAMP for development work in PHP, and am looking for an efficient way to write my includes so that they work properly on both the development and production server when they differ in file structure.  

To illustrate:

My absolute path on my production server is /web/something/someplace/web/site/content/include.php

My absolute path on the development server is
/Applications/MAMP/htdocs/site/content/include.php

How do most people do this in an efficient way without having to rewrite the paths when going from development to production for everything above the site folder?
0
DaveNegron
Asked:
DaveNegron
  • 2
1 Solution
 
mankowitzCommented:
I usually use seomthing like this:

if (!@include '/path/to/production/server') 
     require('/path/to/test/server/');

Open in new window


Another option is to make your files relative to document root, if possible:

require_once($_SERVER['DOCUMENT_ROOT'].'/relative/path/tofile');
0
 
DaveNegronAuthor Commented:
@mankowitz Along these same lines, what do you use when the file is above the document root?
0
 
mankowitzCommented:
To be honest, I usually do not keep documents outside the document root. I understand that this is necessary sometimes, but I find it easier to keep individual copies. In those cases, however where I can't keep the document inside the document root, then I use the first option above.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now