hello all.

i'm developing a gallery but we want to hide the path where the image is stored. is that possible and how?


add a comment

3 Answers

  • Votes
  • Oldest
  • Latest

You cant hide, it but you can make it tuff to find.

add a comment

You can use sessions to block people from visiting the link directly, though there are of course many ways for them to get around it many people don't know how. See this tutorial for protecting stylesheets:
Then use getdata on a single file to take in the image id or name, and use htaccess to rewrite it to .png etc. Have a directory structure such as:

images >

  • view.php
  • .htaccess
  • files >
    • example.gif
    • funny.jpg
    • interesting.png

view.php checks the session, takes in the getdata of the image name, it then looks for the file in the files directory and grabs it then shows the image at the url. So there is one url for them all eg: view.php?img=funny.gif
then use the image handling functions to get the type (image/gif) and use the header('Content-type: image/gif'); and use PHP's image handling functions to show the image.
the role of .htaccess is to hide the files directory, you could also use mod rewrite to spoof the image urls where they actually direct to one location. The whole purpose of this is so you can set the session on the main website then show the pictures there but the direct url to the image can show an alternate image describing "direct linking is disallowed" or such.

^ oops, a messy post 😳 ... just reply and ask me for clarification on individual points

add a comment

It's very much possible but you'll need to do some extra work, and I don't really see the benefit of hiding the image path.

One way of going about this is to have a mapping from a number to the image path, for eg.:

$map = array(
1 => 'abc1/def2.gif',
2 => 'something/xyz.jpg'
3 => 'another_folder/123.png'

You could possibly store this mapping in a database.

And then you can write a script that outputs the image, as Bozebo described:

header('Content-type: image/???');

$id = $_GET['id'];


Then, instead of directly giving the path to the image, you would use something like

<img src="image.php?id=2" />
add a comment