Alex
Alex

Reputation: 9265

local vs remote path definitions

Say I used realpath(dirname(__FILE__)) to get my ROOT path, at which point we get something along the lines of /home/a8122625/public_html/ if I want to use this in script to check whether or not the file exists thats fine, but if I print the ROOT to a, say, image folder so that I can build an image src using it. I will get something along the lines of <img src="/home/a8122625/public_html/images/someimage.jpg"> which comes out with a bad location (for obvious reasons).

I primarily want to define my roots using the aformentioned method since its compatable with windows, so I can develop locally, and have the same path definitions remotely. However for images, I have ended up seeing if user is on localhost or not, and then outputting the proper root as per the requirements of windows or apache.

Is there an all-encompassing way of defining directories as such that I can have the same functionality locally and remotely? What am I doing wrong?

I have found similar questions on stack, however none of which fully address the solution in an all-encompassing manner. I feel as though this question is one that ought to be addressed, and some have more interesting solutions than I can come up with.

Upvotes: 0

Views: 2938

Answers (1)

mario
mario

Reputation: 145512

HTML references are typically relative to the DOCUMENT_ROOT / webserver base url.

File paths in PHP relate to the server root / physical directory structure, thus using {$_SERVER['DOCUMENT_ROOT']} helps with parity.

Upvotes: 1

Related Questions