I have a photo gallery where the user is allowed to download a hires version of the images by clicking a link. I usually use non web safe names for the photo naming convention mainly for design purposes. This causes the PHP script to stop interpreting the file name at the first instance of "%20". So if 50 images have the same name except for a counter, the user will be offered to download the same file name every time.
So... I need to modify the code below to properly interpret file name when it contains "%20".
download.php - this file is in the directory along with hires images.
// Force download of image file specified in URL query string and which
// is in the same directory as this script:
$filename = basename($_GET['img']); // don't accept other directories
$size = @getimagesize($filename);
$fp = @fopen($filename, "rb");
if ($size && $fp)
header("Content-Length: " . filesize($filename));
header("Content-Disposition: attachment; filename=$filename");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("HTTP/1.0 404 Not Found");
This HTML code invokes the download option:
<img src="/images/download.php?img=imagename.jpg" alt="test">
Example: These file names work:
I normally would use this naming convention on the original files, and my gallery design software would add the "%20" to enable the browser to interpret the file name. Which has always worked fine except in this instance, which allows a download of the original image.
Game 1 Hopkins.09.10.01.jpg
Which is: filename:month:year:counte
Sorry for this very long winded description. Just wanted to be clear.