Displaying image stored outside public_html directory

I think I know the answer to this but just to be on the safe side I want to confirm it here.

When you store images outside the public_html directory, then you can NOT display these images like this:

<img src=“…/…/…/not_public_html/images/photo.jpg”>

or like this

<img src=“/home/mydomain/not_public_html/images/photo.jpg”>

Am I right?

That is right.

You would need some sort of script running inside public_html that retrieves the images and passes them to the browser in order to make images outside public_html accessible from the web. That of course has the advantage that the script can also check for other things such as whether they are allowed to see the image before delivering it.

hey denasio … why are you trying to move your images outta the main site … if your worried about unauthorised access, there are better ways to do this … ???

I’m creating a website where users can upload and share their images. I do not want them to hotlink the images. That’s why I want to store them outside the public_html directory. But if I do this, then I would need a script to fetch and display them (like image.php?id=572).

I think I will go ahead and place them in the public_html directory and use hotlink protection in CPanel to prevent hotlinking.