-1

I want to make images shopping site in which I want people buy images then they can download them.
My problem is how to create hidden path to image that people download the image and don't know the real path of the image.

Werner Henze
  • 16,404
  • 12
  • 44
  • 69

2 Answers2

2

You can call a php file to download the image and not the real image/path.

Like this you can call the real path inside your php file with something like:

$path = "/public_html/yourPath/";

if (! isset($_GET['img'])) {
    die("Invalid URL");
}

$imageName = filter_var($_GET['img'], FILTER_SANITIZE_STRING);
$finalPath = $path.$imageName;

header('Content-type: octet/stream');
header('Content-Type: image/jpg');
header("Content-Disposition: attachment; filename=$finalPath;");
readfile($finalPath);

You can read more about it here.

Alvaro
  • 40,778
  • 30
  • 164
  • 336
0

Store the images in an offline location (not www) and retreive them with PHP, so they can access the image for example like this: http://yoursite.com/index.php?file=filename and then PHP will go and return that file from the offline location. You just need to set the correct headers so the content is not treated like a web page but an image instead. Now obviously, such link is still public so you need to add some more information to it to authenticate the downloader.

cen
  • 2,873
  • 3
  • 31
  • 56