Jump to content

Download product image code


phantomeye

Recommended Posts

Hi Guys,

I would like to give my customers the ability to download the product image, without having to right click and save image as. Can you tell me how i can do this. I would like to put a line under the product image that says, "Download image here" when they click, it gives them the option to save the image.

I was going to upload all my images as zips into the download folder, but was wondering if there was a simpler method to download the image directly from the image directory.

Thanks

Link to comment
Share on other sites

This should get you started.

<?php
if(!empty($_GET['img'])) {
 $filename = $_GET['img'];
 $size = @getimagesize($filename);
 $fp = @fopen($filename, "rb");
 if ($size && $fp) {
   // header("Content-type: {$size['mime']}");
   header("Content-Type: application/octet-stream");
   header("Content-Length: " . filesize($filename));
   header("Content-Disposition: attachment; filename=$filename");
   header('Content-Transfer-Encoding: binary');
   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
   fpassthru($fp);
   exit;
 }
}
header("HTTP/1.0 404 Not Found");
?>

Link to comment
Share on other sites

Hi Mr Baseball,

Apologies for not responding earlier, for some reason, i did not receive notification on this post. Thanks once again for your help, this maybe a stupid question, where should i insert this code. I have a button that i have inserted in the pb-left column block in product.tpl

Link to comment
Share on other sites

You can also have a link just below the product image where Print and View large Image is in product.tpl
It is called the useful links "block"
looks something like this:

>
<!-- usefull links-->
</pre>
<ul>
     {if $HOOK_EXTRA_LEFT}{$HOOK_EXTRA_LEFT}{/if}
{l s='Print'}

     {if $have_image && !$jqZoomEnabled}
{l s='View full size'}
     {/if}
</ul>


Then take the code I posted, put it in another php file, place it in your web root and call it like download_image.php
then the link would be made up like this:

getImageLink($product->link_rewrite, $imageIds, 'large')}">{l s='Download Image'}


This should help you finish everything up. This should retrieve the large format image of the product.
If it doesn't put the correct img parameter, play around with the vaules in product.tpl to get the right one.

Link to comment
Share on other sites

Thanks Mr Baseball, will give it a go today and get back to you. Okay, give it a try and nothing happened. If it makes a difference, i am using PS1.4

Heres what i did:

1) Created download_image.php file in my home directory
2) Edited the product.tpl file and added the line you indicated

Let me know which step am i skipping (probably linking product.tpl to download_image.php

Cheers

Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...