Emmanuel O Emmanuel O - 2 years ago 205
PHP Question

Simulate absolute path on XAMPP Server

I am currently working on a server, and I want to work locally on it. So I copied everything.

The problem is that in the code on the server, I include files with absolute paths like this:

include /home/root/html_folder/file.php

I want that this /home/root/html_folder to redirect to


Is there an easy way to do so?

Thank you very much!!

Answer Source

Option one - Relative paths

Relative paths are fairly simple in PHP.

$root = dirname(__FILE__);

// Shorter constant

// To display the path:
echo $root;

// To include a file, no matter where your project is
include $root.DS.'file.php';

Option two - Symbolic Links

Since you have pointed out that all your files use absolute paths the above is not a solution for you.

You could try using symbolic links.

Read about them here

Note: I would still like to suggest making your includes relative. This will save you lots of trouble in the future.

Option three - Mounting

You can also mount your remote filesystem and work on it directly without having to use ssh and work in a console.

You can install SHFS on Mac OSX. You will need to download FUSE and SSHFS from the osxfuse site.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download