Forcing open/save dialog

Phayze

Joined: 2005-10-11
Posts: 4
Posted: Tue, 2005-10-11 11:23

Hi,
First of all, excellent software, aside from a few minor setup issues, it's been a breeze to use and administer.

I'm using Gallery 2 as a resource centre for about 50% images, and the rest pdfs - I want to modify the "Download document" link to not open any pdfs when clicked on, but to give the user a choice of open/save to disk, the standard save dialog box.

Has anyone done this before? I couldn't find anything searching on what I thought were appropriate terms.

Thanks,

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16502
Posted: Tue, 2005-10-11 14:11

I don't think you can get this to work unless you zipped the file or something. Most browsers will see that as a PDF and just open it. I could be wrong though.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
Phayze

Joined: 2005-10-11
Posts: 4
Posted: Tue, 2005-10-11 14:27

It must be possible - I've done it before in .asp and looked into it, but never had to implement it in .php. I could probably hack it out myself, but if someone's done it before, I'd rather not waste my time...

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-10-11 15:18

nope, this wasn't done for g2 before, you wouldn't waste your time ;)
we'd gladly add your patch to g2.

 
Phayze

Joined: 2005-10-11
Posts: 4
Posted: Tue, 2005-10-11 15:53

in /modules/core/DownloadItem.inc, replace line 128;

header('Content-Disposition: inline; filename="' . $data['pseudoFileName'] . '"');

with;

/* pdf force download*/
if ($data['mimeType'] == "application/pdf"){
header('Content-Disposition: attachment; filename="' . $data['pseudoFileName'] . '"');
}else{
header('Content-Disposition: inline; filename="' . $data['pseudoFileName'] . '"');
}
/* pdf force download*/

That was almost too easy...

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2005-10-11 16:10

since we wouldn't apply such a specific patch to such a general function, we'd have to do it slightly different.
1. make it optional
2. make it optional not just for pdf but for a class of mimetypes and you should be able to switch it on / off for each mimetype
3. maybe offer the user a choice (can be hacked in themes etc, but a general, clean solution would be prefereable)

but the header('Content-Disposition: attachment; is the important thing here.

all in all not a minimal fix.
if someone likes the outlined feature. you should file a feature request for it on http://sf.net/projects/gallery/ . then people can vote on http://gallery.menalto.com/sfvote/ .

 
Phayze

Joined: 2005-10-11
Posts: 4
Posted: Tue, 2005-10-11 16:23

Yeah, it was never meant to be a fix-all for everybody, but I don't know enough about the inner workings of g2 to set it up as a fully functioning erm.. function.
But I'd agree that the important thing is a) finding out what the change would be, and b) making it optional per mimetype. If g2 is being used for more than just images, then an optional download would be a good thing I think.

 
g3brown

Joined: 2005-10-03
Posts: 5
Posted: Thu, 2006-01-19 05:02

Could a similar hack be applied to force download of jpegs?

I'm using Gallery 2.0.2 with Sinuix 1.0.2 (from his site). At first I wasn't getting the download link at all as most of my images were < 800x800 and the albums are set at 800x800. When a larger image was present, I would see the download link for that item. To fix that I edited themes/siriux/templates/photo.tpl around line 68.

{* Download *}
{if !empty($theme.sourceImage) &&
    (count($theme.imageViews) > 0 || $theme.sourceImage.mimeType != $theme.item.mimeType)}

I change the 1 into the 0 you see above. I now get my download image link on every image, but I would like it to just download it, as in popping up the download dialog box instead of displaying the image inline with the browser.

I tried following your sample and using image/jpg, but that didn't work.

 
blitz boy

Joined: 2006-01-03
Posts: 10
Posted: Sat, 2006-05-06 20:02

I use Gallery2 mostly for videos, and strongly prefer to have users download media instead of viewing them in the browser. I've applied this core mod to the DownloadItem.inc file.

	header('Content-type: ' . $data['mimeType']);
	/* begin force download */
	if ($data['mimeType'] == "video/quicktime"){
	header('Content-Disposition: attachment; filename="' . $data['pseudoFileName'] . '"');
	}elseif ($data['mimeType'] == "video/mpeg"){
	header('Content-Disposition: attachment; filename="' . $data['pseudoFileName'] . '"');
	}elseif ($data['mimeType'] == "video/x-ms-wmv"){
	header('Content-Disposition: attachment; filename="' . $data['pseudoFileName'] . '"');
	}elseif ($data['mimeType'] == "video/x-msvideo"){
	header('Content-Disposition: attachment; filename="' . $data['pseudoFileName'] . '"');
	}else{
	header('Content-Disposition: inline; filename="' . $data['pseudoFileName'] . '"');
	}
	/* end force download */

It appears to have a conlfict with database cache: the force download only works *once*. By once, I mean when a download link has been clicked for the first time (by anyone), the file will download properly instead of opening in the browser, but for any subsequent clicks (by anyone), the video will open in the browser. When I 'clear database cache' in the Maintenance module, the force download works again, but only once.

If anyone wants to see my gallery for reference, go to -- http://www.flipsider.com/gallery/?g2_itemId=35 -- it's embedded in joomla, if that matters. Gallery 2.1 RC2.

Thanks for any help.

 
junthin

Joined: 2006-09-21
Posts: 2
Posted: Fri, 2006-09-22 17:34

Did anyone get this "Force Save" modification working for the latest Gallery2 (v. 2.1.2)? I tried all the listed modifications and my video files are still not force saving. Any help?