tags:

views:

195

answers:

2

For security purposes, all system, images documents are located outside my website root directory. I dont want to use relative paths because some files are called in difference circumstances, and sometimes they are included inside other files.

I'm looking for an infallible solution to allow me to maintain my system files outside my root directory and access them with absolute paths.

Please read this elaborate explanation:

If I have a page called: "index.php", it would be located inside the directory "root" (thus accessible to everybody). This "index.php" would contain a <img src="..." /> to an image file outside the root, in an adjacent directory to "root", called "images". Sure I could use src="../images/goody.jpeg" but if I included "index.php"'s contents in another file, located elsewhere, this would fall short at getting to "goody.jpeg".

So after badgering about paths, could you help me complete this one:

<img src="?

Thank you!

A: 

Given your description, I would expect <img src="/images/goody.jpeg"> to do what you want.

Edward Loper
A: 

You cannot publicly reference files outside of the public root. That is the whole point of the public root. If ../images/img.jpg works and images/img.jpg is outside of your public root, you have a security issue. The whole point of a public root is to sandbox the public into a confined area of your server. What you are trying to do is allow users to break out of that sandbox.

All public assets (images, css, javascript, etc) should be in the public root or a sub directory under it.

Brad
and what about website logic (such as classes, function .php)?
sombe
That can go anywhere on your server that PHP has access to. Putting it outside of the public root is very typical. In that case, I typically add my library code to the PHP include path and reference some kind of bootstrap relatively (ie. from index.php I include ../bootstrap.php) which then does the real processing of the request.
Brad