• [MOD] Alternate directory for download files. 5 0 5 1
Currently:  

Author Topic: [MOD] Alternate directory for download files.  (Read 193810 times)

0 Members and 1 Guest are viewing this topic.

Offline loz

  • Newbie
  • *
  • Posts: 28
    • View Profile
[MOD] Alternate directory for download files.
« on: April 19, 2005, 04:29:08 PM »
Hi,

Code Update !   http://www.4homepages.de/forum/index.php?topic=7499.msg148451#msg148451 @rembrandt

I'm trying to make an image gallery which will enable users download very big files. The problem is that if I stick these 4mb files into the media folder and into the appropriate category they show up on the detail page.

All I want is to do is to make a separate folder on my server for the big 4mb files which is only available to download when triggered by a user clicking 'download' (and zip download) on the detail page and also when they visit their 'Lightbox' to download the images together. I don't want the big image to load up in a new window, just a simple download.

I've got about 1000 images to upload, so I don't want to assign every image with a download url in the Admin panel.

Ideally I would like to login to the admin panel, go to 'check new images', check for all of them in every category then upload to the database (thumbnails are already in the 'thumbnail' folder on the server). I guess because the images will all have the same filename in each different folder the download buttons just need to be linking to a different folder on the server and then my problem should be solved.

I know there are similar topics on this and I have tried my patience with them all, installed them and they either don't work or aren't quite what I am looking for.

Please help because I can see it being a relatively easy mod and I'm sure will help others who have been confused by the topics like 'Different download options / Verschiedene Download Möglichke' & '[Mod] Image/Media In New Window (easy/more practical)'.

Thanks,

Loz
« Last Edit: June 26, 2010, 06:55:22 PM by Rembrandt »

Offline martrix

  • Hero Member
  • *****
  • Posts: 755
    • View Profile
    • overlord.cz
Re: [MOD] Alternate directory for download files.
« Reply #1 on: April 19, 2005, 05:11:37 PM »
Try to search for phpThumb on the forum and on Google...

it will partially increase the server's computing time, but if caching is on and working well, than it will only be for the first time a user opens a page-detail.

In that case: a smaller picture of a max-size would be shown on the details page and the download buttong would lead directly to the huge file...

without needs to change the php-code of 4images...
and you can upload the files once and as you are used to  :o
MAяTRIX


Offline loz

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #2 on: April 19, 2005, 05:17:39 PM »
Hi,

Thanks for that but I don't want to use that method because as you say it will increase server load especially if lots of people are doing the same thing - it's 4mb each file!

Please advise of a way to change the download button to link to the larger files and it will stop me pestering you - honest!

Thanks, Loz

Offline martrix

  • Hero Member
  • *****
  • Posts: 755
    • View Profile
    • overlord.cz
Re: [MOD] Alternate directory for download files.
« Reply #3 on: April 19, 2005, 05:26:18 PM »
It was just an advice...  :) because I don't know it better  :wink:

Take it or leave it  :wink:

But I do not really agree: once the "thumbnail" is created, the thumbnail cache works well and the cache-timeout is set well it won't increase the server-load more than once per file - no matter how many times the image will be shown  :)
MAяTRIX


Offline loz

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #4 on: April 19, 2005, 06:14:59 PM »
One other thing I would need is for the filesize info on the details page to be same as the downloadable image, not the detail page image. Hope someone can help.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #5 on: April 20, 2005, 02:53:59 AM »
Lucky you!  I've already done this.  :wink:

Open download.php, locate this line:
Code: [Select]
    $file['file_path'] = (is_local_file($image_row['image_media_file'])) ? dirname($image_row['image_media_file'])."/".$file['file_name'] : MEDIA_PATH."/".$image_row['cat_id']."/".$file['file_name'];
Change it to:
Code: [Select]
//    $file['file_path'] = (is_local_file($image_row['image_media_file'])) ? dirname($image_row['image_media_file'])."/".$file['file_name'] : MEDIA_PATH."/".$image_row['cat_id']."/".$file['file_name'];
    // Let the user download the "<cat_id>/download/<fname>", "<cat_id>/big/<fname>", or "<cat_id>/<fname>" version of the image
$temp = get_file_path($file['file_name'], "download", $image_row['cat_id'], 0, 1);
if( !file_exists($temp) )
  $temp = (is_local_file($image_row['image_media_file'])) ? dirname($image_row['image_media_file'])."/".$file['file_name'] : MEDIA_PATH."/".$image_row['cat_id']."/".$file['file_name'];
$file['file_path'] = $temp;

Open includes/functions.php and locate this code:
Code: [Select]
    if ($file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'])) {
      $file_size = format_file_size($file_size);
    }

Immediately after that, add this:
Code: [Select]
// CTN download file block insert BEGIN
if( file_exists(MEDIA_PATH."/".$image_row['cat_id']."/download/".$image_row['image_media_file']) )
  $download_file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/download/".$image_row['image_media_file']);
    elseif( file_exists(MEDIA_PATH."/".$image_row['cat_id']."/big/".$image_row['image_media_file']) )
  $download_file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/big/".$image_row['image_media_file']);
    $download_file_size = format_file_size($download_file_size);
// CTN download file block insert END

Locate:
Code: [Select]
  $file_size = "n/a";
  if (!is_remote($image_row['image_media_file'])) {
    if ($file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'])) {
      $file_size = format_file_size($file_size);
    }
  }
  elseif ($detailed_view) {
    $file_size = get_remote_file_size($image_row['image_media_file']);
  }

Replace with:
Code: [Select]
  $file_size = "n/a";
  $download_file_size = "n/a";  // Download file
  if (!is_remote($image_row['image_media_file'])) {
    if ($file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'])) {
  $download_file_size = $file_size;  // Download file
      $file_size = format_file_size($file_size);
    }
// Download file Block BEGIN
if( file_exists(MEDIA_PATH."/".$image_row['cat_id']."/download/".$image_row['image_media_file']) )
  $download_file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/download/".$image_row['image_media_file']);
    elseif( file_exists(MEDIA_PATH."/".$image_row['cat_id']."/big/".$image_row['image_media_file']) )
  $download_file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/big/".$image_row['image_media_file']);
    $download_file_size = format_file_size($download_file_size);
// Download file Block END
  }
  elseif ($detailed_view) {
    $file_size = get_remote_file_size($image_row['image_media_file']);
  }

Locate:
Code: [Select]
    "url_download" => $site_sess->url(ROOT_PATH."download.php?".URL_IMAGE_ID."=".$image_row['image_id']),
Add after:
Code: [Select]
    "download_image_file_size" => $download_file_size,  // Download file
Locate:
Code: [Select]
    if ($image_info = @getimagesize($src, $info)) {
      $width_height = " ".$image_info[3];
      $width = $image_info[0];
      $height = $image_info[1];

Add after:
Code: [Select]
      $download_width_height = $width_height; // Download file
      $download_width = $width; // Download file
      $download_height = $height; // Download file

Locate:
Code: [Select]
  else {
    $check_handle = "check_".$image_type."_type";
    $path = (($image_type == "media") ? (($cat_id) ? MEDIA_PATH."/".$cat_id : MEDIA_TEMP_PATH) : (($cat_id) ? THUMB_PATH."/".$cat_id : THUMB_TEMP_PATH))."/".$file_name;
    return ($check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is", $file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" : $path) : $return_code;
  }

Replace with:
Code: [Select]
  else {
    $check_handle = "check_".$image_type."_type";
//    $path = (($image_type == "media") ? (($cat_id) ? MEDIA_PATH."/".$cat_id : MEDIA_TEMP_PATH) : (($cat_id) ? THUMB_PATH."/".$cat_id : THUMB_TEMP_PATH))."/".$file_name;
//    return ($check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is", $file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" : $path) : $return_code;
// Download file block insert BEGIN
    switch( $image_type ) {
  case "media":
    if( $cat_id )
      $path = MEDIA_PATH."/".$cat_id;
else
  $path = MEDIA_TEMP_PATH;
    break;
      case "big":
        $path = MEDIA_PATH."/".$cat_id."/big";
    break;
      case "download":
        $path = MEDIA_PATH."/".$cat_id."/download";
    break;
  default:
    if( $cat_id )
      $path = THUMB_PATH."/".$cat_id;
else
  $path = THUMB_TEMP_PATH;
    break;
}
$path .= "/".$file_name;
// Download file block insert END
    return ($check_handle($file_name) && file_exists($path)) ? (($in_admin && !preg_match("#(gif|jpg|jpeg|png)$#is", $file_name)) ? ICON_PATH."/".get_file_extension($file_name).".gif" : $path) : (($image_type != "big" && $image_type != "download") ? $return_code : ""); // Download file :: V@no big mod
  }

Locate:
Code: [Select]
    $site_template->register_vars(array(
      "media_src" => $media_src,
      "media_icon" => $media_icon,
      "image_name" => $image_name,
      "width_height" => $width_height,
      "width" => $width,
      "height" => $height,
      "iptc_info" => $iptc_info
    ));

Replace with:
Code: [Select]
// Download file info insert BEGIN
    $download_file_src = get_file_path($media_file_name, "download", $cat_id, 0, 1);
    $src_download = (!file_exists($download_file_src) && file_exists(preg_replace("/\/{2,}/", "/", get_document_root()."/".$download_file_src))) ? preg_replace("/\/{2,}/", "/", get_document_root()."/".$download_file_src) : $download_file_src;
    if ($temp = @getimagesize($src_download)) {
      $download_width_height = " ".$temp[3];
      $download_width = $temp[0];
      $download_height = $temp[1];
    }
// Download file info insert END

    $site_template->register_vars(array(
      "media_src" => $media_src,
      "media_icon" => $media_icon,
      "image_name" => $image_name,
      "width_height" => $width_height,
      "width" => $width,
      "height" => $height,
      "download_width" => $download_width, // Download file
      "download_height" => $download_height, // Download file
      "iptc_info" => $iptc_info
    ));

Replace the very last line:
Code: [Select]
?>
With:
Code: [Select]
// Download file block insert BEGIN
function check_remote_download($remote_media_file) {
  global $config;
  return (preg_match("#^(https?:\/\/[a-z0-9\-]+?\.([a-z0-9\-]+\.)*[a-z]+(:[0-9]+)*\/.*?\.(".$config['allowed_mediatypes_match'].")$)#is", $remote_media_file)) ? 1 : 0;
}
function check_local_download($local_media_file) {
  global $config;
  return (preg_match("#^((\.)*\/.*?\.(".$config['allowed_mediatypes_match'].")$)#is", $local_media_file)) ? 1 : 0;
}
function check_download_type($file_name) {
  global $config;
  return (in_array(get_file_extension($file_name), $config['allowed_mediatypes_array'])) ? 1 : 0;
}
// Download file block insert END
?>

Open details.html and add something like this to use the new download information:
Code: [Select]
          <tr>
            <td>{download_image_file_size} [{download_width}x{download_height}]</td>
          </tr>

With these changes you can place your download files in a subdirectory under the category id folder where you upload your images using FTP.

So the code will look for your download images in:

category_id/download
category_id

Your download image files must have the same name as the image file used on the details page.  Just upload everything using FTP and the CHECK NEW IMAGES admin CP function.

Offline loz

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #6 on: April 20, 2005, 12:29:42 PM »
Hi Chris,

I've just tried it and it doesn't work. I'm getting error messages when clicking 'Download', saying:

Code: [Select]
Fatal error: Call to undefined function: check_download_type() in /usr/local/psa/home/vhosts/mydomain.com/httpdocs/4images/includes/functions.php on line 120

Are you using an older version? Mine's 1.7.1

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [MOD] Alternate directory for download files.
« Reply #7 on: April 20, 2005, 02:47:29 PM »
I dont see any reference to check_download_type neither in v1.7.1 itself nor in the code Chris posted...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #8 on: April 21, 2005, 12:23:41 AM »
 :oops: Sorry, I had a feeling I was leaving something out.  I'll update the previous post

Turns out I missed quite a lot.  Try it now and see if it's any better

Offline loz

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #9 on: April 22, 2005, 11:36:42 AM »
Congratulations Chris.......... SUCCESS!!!

Just one change I had to make in order for your MOD to work was to ignore this first bit of code change in includes/functions.php:

FIND:
    if ($file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'])) {
      $file_size = format_file_size($file_size);
    }


Immediately after that, add this:

Code:
// CTN download file block insert BEGIN
   if( file_exists(MEDIA_PATH."/".$image_row['cat_id']."/download/".$image_row['image_media_file']) )
     $download_file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/download/".$image_row['image_media_file']);
    elseif( file_exists(MEDIA_PATH."/".$image_row['cat_id']."/big/".$image_row['image_media_file']) )
     $download_file_size = @filesize(MEDIA_PATH."/".$image_row['cat_id']."/big/".$image_row['image_media_file']);
    $download_file_size = format_file_size($download_file_size);
// CTN download file block insert END

-------------------------------
I think this was left in from the original code you made. If you made this change and then tried to make the next change you wouldn't find the script to change!!! Let me know if it's any different.

Another problem is that when you add the image to the lightbox, you don't download the big/downloadable file but the detail page image instead. I'd really appreciate it if you could solve this.

Once you've updated it and fixed the lightbox problem, this is a great simple MOD. You don't have to trail through loads of posts and several updates like this board has. Someone should really clean up the code and make it available on the first page (or set-up a new Completed MODs page).


Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #10 on: April 23, 2005, 02:17:46 AM »
Frankly my time is so limited this time of year and it gets even less available during the summer.  I'll see what I can do.

Offline loz

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #11 on: April 25, 2005, 03:05:10 PM »
Please can you tell me how to fix the Lightbox problem. When you add the image to the lightbox, you don't download the 'big/downloadable' folder file/s but the detail page image/s instead. I really need the large images downloading in the Lightbox download. Please help! Thanks.

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #12 on: April 26, 2005, 02:01:13 AM »
Please be more specific next time.  The download works find from the download link under the thumbnails when viewing the images.  You must be talking about the zip download which wasn't obvious to me.

Open download.php and locate:
Code: [Select]
        $file_path = MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'];
Replace it with:
Code: [Select]
//        $file_path = MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'];
// Download file block insert BEGIN
    // Let the user download the "<cat_id>/download/<fname>", "<cat_id>/big/<fname>", or "<cat_id>/<fname>" version of the image
$file_path = MEDIA_PATH."/".$image_row['cat_id']."/download/".$image_row['image_media_file'];
if( !file_exists($file_path) )
      $file_path = MEDIA_PATH."/".$image_row['cat_id']."/big/".$image_row['image_media_file'];
if( !file_exists($file_path) )
  $file_path = MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'];
// Download file block insert END

Offline loz

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #13 on: April 26, 2005, 09:57:28 AM »
That's great Chris, thanks very much (again).

One question, would it be possible to change the 'send ecard' so it sends the recipient the big/downloadable image via email but still has the detail page image as the preview? (I hope this question is clear)

Thanks for all your help, it's really appreciated!

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: [MOD] Alternate directory for download files.
« Reply #14 on: April 26, 2005, 02:44:05 PM »
That's a big departure from the current behavior of sending a link to the details page by email.  So no, I don't have the time or the interest to do that much coding.  Sorry.

Honestly, if the user gets the postcard link, you can just edit your template and category permissions to allow them to download the larger image from there.

 

Post your comments here