Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1] 2 3   Go Down

Author Topic: Modification to create image download link  (Read 73616 times)

0 Members and 1 Guest are viewing this topic.

adrianbj

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 34
Modification to create image download link
« on: July 05, 2005, 02:26:28 am »

First of all, I tried to add this post to modifications, but I didn't have rights to post a new topic, so here goes. Something that has always bugged me a little about Coppermine was that clicking on the normal size image spawns a new window containing the fullsize version. I think it would be better (especially for non-tech users) that there is a download link to the full version. Sometimes these images can be many MB in size and a user may not realize this until their browser starts to download it. I have made a modification myself to address this and thought I'd share it with anyone else who might be interested.

I used to use version 1.3 and so the code to be modified was in the displayimage.php file, but I have just installed 1.41 and it now appears that you have to make this mod to the theme.php file.
Here are my changes:

Code: [Select]
// The original content of theme.php (note this is only present in the sample theme)

    if ($mime_content['content']=='image') {
        if (isset($image_size['reduced'])) {
            $winsizeX = $CURRENT_PIC_DATA['pwidth']+5;  //the +'s are the mysterious FF and IE paddings
            $winsizeY = $CURRENT_PIC_DATA['pheight']+3; //the +'s are the mysterious FF and IE paddings
            $pic_html = "<a href=\"javascript:;\" onclick=\"MM_openBrWindow('displayimage.php?pid=$pid&amp;fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=yes,status=yes,resizable=yes,width=$winsizeX,height=$winsizeY')\">";
            $pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
            $pic_html .= "<img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
            $pic_html .= "</a>\n";


// My modification below creates a download link showing the size of the image and prevents opening of fullsize image in new window

    if ($mime_content['content']=='image') {
    if (isset($image_size['reduced'])) {
        $filesize = $CURRENT_PIC_DATA['filesize'];
$filesizecorr = intval($filesize/1024);
$winsizeX = $CURRENT_PIC_DATA['pwidth'] + 16;
        $winsizeY = $CURRENT_PIC_DATA['pheight'] + 16;
$picturefs_url = str_replace("normal_", "", $picture_url);
        $pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
        $pic_html .= "<center><img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /></center><br />";
$pic_html .= "<center><a href=\"download.php?getfile=$picturefs_url\">Click here to save the fullsize ($filesizecorr KB) image directly to your hard drive<br /></a><br /><br /></center>";
      $pic_html .= "</a>\n";

You will also need to create a new file called download.php in the root of your coppermine installation with these contents

Code: [Select]
<?php
     
if ($_REQUEST ['getfile']){
        
$file $_REQUEST ['getfile'];
     
     }

$save_as_name basename($file);   
ini_set('session.cache_limiter''');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
header("Content-Type: application/octet-stream");
header("Content-Disposition: disposition-type=attachment; filename=\"$save_as_name\"");

readfile($file);

?>

Anyway, hope that is useful to someone.

Adrian


« Last Edit: July 05, 2005, 07:55:37 am by GauGau »
Logged

HanOverFist

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Modification to create image download link
« Reply #1 on: July 05, 2005, 08:27:09 pm »

everything seems to work but when I click the link I'm getting strange DL problems.
file sizes are over 1.5 meg do not fully DL
The DL dialog box finishes transfering the file but when trying to open the file I get a corrupt or truncated file error message.
Server setting?
CPG 1.3.3
Logged

HanOverFist

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Modification to create image download link
« Reply #2 on: July 11, 2005, 08:36:25 pm »

I would love to get a reply here.
cpg133 with this mod truncates every file over 1.9 megs at 2,000,000 bytes.
cpg141 with this mod truncates every file over 1.9 megs at 2,000,000 bytes.
Everytime.
Is this a php server setting that is doing this.
It would be great to get this resolved.
Is there any more info you need from me for a response?

Jay
Logged

Nibbler

  • Guest
Re: Modification to create image download link
« Reply #3 on: July 11, 2005, 09:37:34 pm »

Read the comments in the php manual for readfile().
Logged

HanOverFist

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Modification to create image download link
« Reply #4 on: July 11, 2005, 10:12:41 pm »

thanks nibbler

That is what I was looking for.
now where do I insert this bit of code?

<?php
function readfile_chunked($filename,$retbytes=true) {
   $chunksize = 1*(1024*1024); // how many bytes per chunk
   $buffer = '';
   $cnt =0;
   // $handle = fopen($filename, 'rb');
   $handle = fopen($filename, 'rb');
   if ($handle === false) {
       return false;
   }
   while (!feof($handle)) {
       $buffer = fread($handle, $chunksize);
       echo $buffer;
       ob_flush();
       flush();
       if ($retbytes) {
           $cnt += strlen($buffer);
       }
   }
       $status = fclose($handle);
   if ($retbytes && $status) {
       return $cnt; // return num. bytes delivered like readfile() does.
   }
   return $status;

}
?>



In the new download.php file that I created on line 15? (replacing the instance of readfile?)
or do I make a new php file out of it called readfile.php?

tia

Jay
Logged

Nibbler

  • Guest
Re: Modification to create image download link
« Reply #5 on: July 11, 2005, 10:15:09 pm »

You place the function definition somewhere in the file before the call to read($file), and replace the call to read($file) with readfile_chunked($file);
Logged

HanOverFist

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
Re: Modification to create image download link
« Reply #6 on: July 11, 2005, 10:22:06 pm »

sweeeeet

Thank you
Logged

serhathakan

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Modification to create image download link
« Reply #7 on: July 15, 2005, 01:04:04 am »

i am using 1.3.2 and the original code is different and

when i change it to

Code: [Select]
if ($mime_content['content']=='image') {
    if (isset($image_size['reduced'])) {
        $filesize = $CURRENT_PIC_DATA['filesize'];
$filesizecorr = intval($filesize/1024);
$winsizeX = $CURRENT_PIC_DATA['pwidth'] + 16;
        $winsizeY = $CURRENT_PIC_DATA['pheight'] + 16;
$picturefs_url = str_replace("normal_", "", $picture_url);
        $pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
        $pic_html .= "<center><img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /></center><br />";
$pic_html .= "<center><a href=\"download.php?getfile=$picturefs_url\">Click here to save the fullsize ($filesizecorr KB) image directly to your hard drive<br /></a><br /><br /></center>";
    $pic_html .= "</a>\n";



it giving error

and my original code is



Code: [Select]
if ($mime_content['content']=='image') {
        if (isset($image_size['reduced'])) {
            $winsizeX = $CURRENT_PIC_DATA['pwidth'] + 16;
            $winsizeY = $CURRENT_PIC_DATA['pheight'] + 16;
            $pic_html = "<a href=\"javascript:;\" onClick=\"MM_openBrWindow('displayimage.php?pid=$pid&fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=yes,status=yes,resizable=yes,width=$winsizeX,height=$winsizeY')\">";
            $pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
            $pic_html .= "<img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
            $pic_html .= "</a>\n";
Logged

Nibbler

  • Guest
Re: Modification to create image download link
« Reply #8 on: July 15, 2005, 01:15:23 am »

Are we allowed to know the error that it gives you ?
Logged

serhathakan

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Modification to create image download link
« Reply #9 on: July 15, 2005, 01:52:56 am »

sure here is the code

Code: [Select]
Parse error: parse error, unexpected $ in /home/tasarim/public_html/galeri/displayimage.php on line 646
Logged

Loki66

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
Re: Modification to create image download link
« Reply #10 on: July 16, 2005, 12:59:53 am »

Is there a way to protect the image using this download ? Is it possible to put images in protected directories ?

Thanks,

L
Logged

serhathakan

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Modification to create image download link
« Reply #11 on: July 16, 2005, 02:34:28 am »

no not protected
chmod 777
Logged

adrianbj

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 34
Re: Modification to create image download link
« Reply #12 on: August 05, 2005, 08:43:45 am »

Well thanks everyone for improving on my mod. I didn't have any download problems on my server with my php settings so I didn't realize the need for the chunkfile way of doing things. I have my the changes to my setup also.

Cheers,

A.
Logged

BT-loader

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 102
Re: Modification to create image download link
« Reply #13 on: August 25, 2005, 10:01:06 pm »

I´ve just installed this mod/hack but it seems that there is an error when saving the image to my hard drive.  :\'(
The image is saved as "document" without any extension, why is that?

(I´m using 1.3.3)

EDIT:  Nevermind, i finally got it to work.

Thanks for a great mod.  ;D
« Last Edit: August 25, 2005, 10:08:45 pm by BT-loader »
Logged
:: BT-loader ::
"The one and only..."

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Modification to create image download link
« Reply #14 on: August 26, 2005, 08:06:30 am »

EDIT:  Nevermind, i finally got it to work.
Then why don't you tell others who might have the same issues you were having? Be a giver instead of always being a taker.
Logged

BT-loader

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 102
Re: Modification to create image download link
« Reply #15 on: August 26, 2005, 02:38:32 pm »

Quote from: GauGau
Then why don't you tell others who might have the same issues you were having? Be a giver instead of always being a taker.
It was a stupid thing really, i just forgot to copy all the code.  :-[

Quote from: adrianbj
// My modification below creates a download link showing the size of the image and prevents opening of fullsize image in new window

    if ($mime_content['content']=='image') {
    if (isset($image_size['reduced'])) {
        $filesize = $CURRENT_PIC_DATA['filesize'];
$filesizecorr = intval($filesize/1024);
$winsizeX = $CURRENT_PIC_DATA['pwidth'] + 16;
        $winsizeY = $CURRENT_PIC_DATA['pheight'] + 16;
$picturefs_url = str_replace("normal_", "", $picture_url);
        $pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
        $pic_html .= "<center><img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /></center><br />";
$pic_html .= "<center><a href=\"download.php?getfile=$picturefs_url\">Click here to save the fullsize ($filesizecorr KB) image directly to your hard drive<br /></a><br /><br /></center>";
    $pic_html .= "</a>\n";
Quote
Logged
:: BT-loader ::
"The one and only..."

mylogon

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 59
Re: Modification to create image download link
« Reply #16 on: August 30, 2005, 10:47:39 pm »

Any thought on how to modify the code for pictures that are resized and therefore will not cause either the "Normal" view or create the download link because they do not trigger that section?

Anyone have any ideas?
« Last Edit: September 08, 2005, 01:11:26 am by mylogon »
Logged

shniz123

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Modification to create image download link
« Reply #17 on: September 03, 2005, 07:34:57 pm »

Works like a champ! Great work.
Logged

outpatient

  • Coppermine newbie
  • Offline Offline
  • Gender: Female
  • Posts: 10
    • My Family Album
Re: Modification to create image download link
« Reply #18 on: September 18, 2005, 08:09:29 pm »

Hey kids,

I'm looking for a mod to stop my videos from playing automatically and to offer a download link as an option.  I know there was one that worked just for the videos, because I've used it before, only I can't for the life of me, find it.  ::)

Would this mod make all images available for download? Can someone point me in the right direction?

I'd really appreciate it, thanks


eta: nevermind, I found it!  ;) here
« Last Edit: September 18, 2005, 08:20:09 pm by outpatient »
Logged

EtaBeta

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: Modification to create image download link
« Reply #19 on: January 21, 2006, 05:52:02 pm »

Hi!
Nice mod!
Is it possible to allow ONLY registerd users to download? How??? I am very iterested to this modification because iI don' want all the visitors be able to download pictures from my gallery.
Thanks to all
Logged
Pages: [1] 2 3   Go Up
 

Page created in 0.075 seconds with 21 queries.