Solved

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

Posted on 2014-01-05
3
758 Views
Last Modified: 2014-01-09
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
Comment
Question by:DaveNegron
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
Comment Utility
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
 

Author Comment

by:DaveNegron
Comment Utility
@mankowitz Along these same lines, what do you use when the file is above the document root?
0
 
LVL 24

Expert Comment

by:mankowitz
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now