how2? download button/icon next to image (g1.44)

versace

Joined: 2005-02-10
Posts: 3
Posted: Thu, 2005-02-10 18:31

hi,

i'm looking for a tip on how to have a button or icon
next to the images in the album, that let (stupid) users
download the high or midres image.

believe me, there are a lot of people out there that
dont know rightclick/save as and cant understand
that difficult concept.

thanks, marco

Powered by Gallery v1.4.4-pl4
------------------------------------------

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Fri, 2005-02-11 06:25

Save this as download.php and put in your gallery directory.

<?php
require(dirname(__FILE__) . '/init.php');
	if (!$gallery->user->canReadAlbum($gallery->album)) {
	echo _("You are no allowed to perform this action !");
	exit;
	}
$filename = $HTTP_GET_VARS['filename'];
// prevent the tampering with the get request, eg... 
// download.php?filename=../../windows/system32/file 
// strip fwd & bkwd slashes
$filename = str_replace('/', '', $filename); 
$filename = str_replace('\\', '', $filename);
$mydir = $gallery->app->albumDir . "/" . $gallery->album->fields['name'];
$path = $mydir."/".$filename; 
$file = basename($path); 
$size = filesize($path); 

header ("Content-Type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=$file"); 
header("Content-Length: $size"); 

readfile($path); 
?>

then save this as /html_wrap/inline_photo.frame
It will place a link under the photo to download the full image.

<?php
/* $Id: inline_photo.frame.default,v 1.5 2004/03/02 14:10:38 jenst Exp $ */
?>
<?php
	include (dirname(__FILE__) . '/inline_imagewrap.inc');
$photo = $gallery->album->getPhoto($GLOBALS["index"]);
$type = $photo->image->type;
$fileName = $photo->image->name . "." . $type;
echo "\n<a href=\"" . makeGalleryUrl("download.php", array("filename" => $fileName)) . '">['. _("download this item") ."]</a>\n";
?>

Let me know if it works as I only tested it on my 1.5B system.

Dave

 
versace

Joined: 2005-02-10
Posts: 3
Posted: Fri, 2005-02-11 08:54

yay! success : )

small change: saved the .frame file as .frame.default, and it works great on
1.44 hosted at opensourcehost.com

dave, dankeschoen from germany

 
fryfrog

Joined: 2002-10-30
Posts: 3236
Posted: Fri, 2005-02-11 11:00

You probably don't want to use the ".default" extension, unless for some reason the other didn't work? If you ever update gallery you will be wondering why your modification got borked :)

You should copy the something.default to just something. Sorry, in edit mode and I can't see the actual filename. You should end up with two files, and gallery only uses the ".default" one if it can't find the other.

 
versace

Joined: 2005-02-10
Posts: 3
Posted: Fri, 2005-02-11 11:14

yupp, that's correct.

xxx.frame <--this one is modified
xxx.frame.default . <--not modified.

if anyone wants to look> http://www.mmacm.info/gallery/, its a website for a photographer.

thanks, marco

 
gelatin

Joined: 2003-10-29
Posts: 10
Posted: Mon, 2005-08-22 14:31

this mod works fine and great if gallery is standalone.
so i get a download link looking like
http://www.gelitin.net/gallery/download.php?filename=stoll.jpg
so this link works!

but i have gallery integrated into Mambvo 4.5.2
then i following download link is generated
http://www.gelitin.net/mambo/index.php?filename=rabbit_total.jpg&option=com_gallery&Itemid=28&include=download.php
this link does not work. the image seems to be corrupted...

any solutions for this?
is it possible to change code of download.php to make it working in Mambo?

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2005-08-23 01:22

I can't test but you should be able to edit this line: echo "\n<a href=\"" . makeGalleryUrl("download.php", array("filename" => $fileName)) . '">['. _("download this item") ."]</a>\n"; to something like echo "\n<a href=\"http://YOUESITE.COM/gallery/download.php&filename=" . $fileName .">download this item"</a>\n";

 
gelatin

Joined: 2003-10-29
Posts: 10
Posted: Tue, 2005-08-23 13:33

Thanks for the hint...
i changed your suggestion to

Quote:
echo "\n<p><a href=\"http://www.MYDOMAIN.net/gallery/" . makeGalleryUrl("download.php", array("filename" => $fileName)) . '">['. _("download this image in high resolution") ."]</a>\n";

Now it works.
Great!

 
isinhabr
isinhabr's picture

Joined: 2006-07-18
Posts: 2
Posted: Tue, 2006-07-18 03:18

Hi

This work with Gallery 2?

Thank you

 
MissLaura

Joined: 2005-06-28
Posts: 10
Posted: Sat, 2006-09-02 18:37

hi, i've just tried this on my gallery which is v.1.5.4.

It works great on mozilla firefox when either using the download and open option or the download and save.

But on IE6 after using the 'open' option and after downloading i get a message saying that real player cant find the file, its looking in my temporary internet folders for it, but nothing can be found that matches the file name.

is there something in the code that i should be changing?

or is it something to do with my internet dowload settings for IE?

any help would be great.. thanks

http://getoffmeyoubummer.dreamhosters.com/gallery

 
scrooks
scrooks's picture

Joined: 2006-09-17
Posts: 1
Posted: Mon, 2006-09-18 01:39

Can some kind soul provide the same kind of information for Gallery 2?

 
gelatin

Joined: 2003-10-29
Posts: 10
Posted: Tue, 2007-04-24 12:08

I successfully used the download.php script mentioned in this thread...
Now since the server (Apache/1.3.33 (Darwin) PHP/5.2.1) changed its PHP to 5.2.1
using Entropy.ch PHP5-Package the script does not work...

clicking the download link so far downloaded the requested image.
now it downloads an empty file with the name of the Album...
looks like a path problem...

what to do?

and yes i would like to stay with PHP5

and the download.php (download whole album as Zip archive) from
gallery 1.5.6 is working properly. Is it possible to change this script to download single files, not the whole Album?

 
gelatin

Joined: 2003-10-29
Posts: 10
Posted: Tue, 2007-04-24 14:35

solved the problem myself.
in file download.php i had to change
$filename = $HTTP_GET_VARS['filename']; to
$filename = $_GET['filename'];
because of PHP 5.2.1

and changed in my .htaccess file and in php_value.template
<IfModule mod_php4.c> to
<IfModule mod_php5.c>

 
instinctive

Joined: 2007-07-15
Posts: 5
Posted: Thu, 2007-11-01 06:58

For Gallery 2:

In modules/core/templates/blocks/PhotoSizes.tpl (for example):

{assign var=foo value=$theme.imageViews[$theme.imageViewsIndex].id}
<a href="{g->url arg1="view=core.DownloadItem" arg2="itemId=$foo" arg3="dl=1"}">
{g->text text="Download %s" arg1=$theme.sourceImage.itemTypeName.1}
</a>

In modules/core/DownloadItem.inc:

Find this line:

$requestMethod = strtolower(GalleryUtilities::getServerVar('REQUEST_METHOD'));

And add / change the following lines as follows:

$dl = (int) GalleryUtilities::getRequestVariables('dl');

$phpVm->header('Content-type: ' . ($dl?'application/octet-stream':$data['mimeType']));
$phpVm->header('Content-Disposition: '.($dl?'attachment':'inline').'; filename="' . $data['pseudoFileName'] . '
$stats = $platform->stat($data['derivativePath']);
$phpVm->header('Last-Modified: ' . GalleryUtilities::getHttpDate($stats[9]));
$phpVm->header('Expires: ' . GalleryUtilities::getHttpDate(time() + 31536000));

(Most of the credits go to jmullan from #gallery on irc.freenode.net)

 
eyermannJAY

Joined: 2008-02-16
Posts: 1
Posted: Sat, 2008-02-16 22:21

I'm also looking to add a download button to by gallery 2.

I used the instructions from above by adding

{assign var=foo value=$theme.imageViews[$theme.imageViewsIndex].id}
<a href="{g->url arg1="view=core.DownloadItem" arg2="itemId=$foo" arg3="dl=1"}">
{g->text text="Download %s" arg1=$theme.sourceImage.itemTypeName.1}
</a>

to -> modules/core/templates/blocks/PhotoSizes.tp
which added the download button.

but for the second part i swaped some of the the code in modules/core/DownloadItem.inc with

$dl = (int) GalleryUtilities::getRequestVariables('dl');

$phpVm->header('Content-type: ' . ($dl?'application/octet-stream':$data['mimeType']));
$phpVm->header('Content-Disposition: '.($dl?'attachment':'inline').'; filename="' . $data['pseudoFileName'] . '
$stats = $platform->stat($data['derivativePath']);
$phpVm->header('Last-Modified: ' . GalleryUtilities::getHttpDate($stats[9]));
$phpVm->header('Expires: ' . GalleryUtilities::getHttpDate(time() + 31536000));

as discribed but this causes my thumbnails to go missing and doesn't allow me to download the images any way. Is there any who got these instructions to work?

 
mpallo

Joined: 2007-01-26
Posts: 10
Posted: Tue, 2009-01-13 21:33

Anyone get any of this code working stable with 2.1?

 
achernen

Joined: 2010-01-20
Posts: 1
Posted: Wed, 2010-01-20 21:45

I managed to get this working for gallery2 as follows:

I used this as above to add the Download link in modules/core/templates/blocks/PhotoSizes.tpl:

{assign var=foo value=$theme.imageViews[$theme.imageViewsIndex].id}
<a href="{g->url arg1="view=core.DownloadItem" arg2="itemId=$foo" arg3="dl=1"}">
{g->text text="Download %s" arg1=$theme.sourceImage.itemTypeName.1}
</a>

and then in modules/core/classes/Gallery.class I changed the following line:

header('Content-Disposition: inline; filename="' . $filename . '"');
to:
header('Content-Disposition: attachment; filename="' . $filename . '"');

and it worked perfectly.