Force uploaded image to download when link is clicked.
2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 20, 2011 (RSS)
By Mikey - June 20, 2011
I need to force images that have been uploaded to a photo gallery to download once the "Download Photo" link has clicked.
Anyone have any suggestions how to get the photos to download... instead of loading in the browser window? I'm open to using a form if there's a solution.
Anyone have any suggestions how to get the photos to download... instead of loading in the browser window? I'm open to using a form if there's a solution.
<?php foreach ($galleryRecord['gallery'] as $upload): ?>
<a href="<?php echo $upload['urlPath'] ?>">Download Photo<?php echo $upload['info1'] ?></a>
<?php endforeach ?>
Re: [zick] Force uploaded image to download when link is clicked.
By robin - June 20, 2011
Hey zick,
If you want to force a download you'll need to use an intermediate script that sends the download headers to the browser. You can pass the image num as a parameter to the script so it knows what file to send.
Here is a good php function to use and some examples:
http://php.net/manual/en/function.readfile.php
Your Download link might look like:
Hope that helps,
Robin
If you want to force a download you'll need to use an intermediate script that sends the download headers to the browser. You can pass the image num as a parameter to the script so it knows what file to send.
Here is a good php function to use and some examples:
http://php.net/manual/en/function.readfile.php
Your Download link might look like:
<?php foreach ($galleryRecord['gallery'] as $upload): ?>
<a href="downlaod.php?num=<?php echo $upload['num'] ?>">Download Photo<?php echo $upload['info1'] ?></a>
<?php endforeach ?>
Hope that helps,
Robin
Robin
Programmer
interactivetools.com
Programmer
interactivetools.com