4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: Fred on June 11, 2003, 11:09:26 PM

Title: Add text to filename in Download an Zip-Download
Post by: Fred on June 11, 2003, 11:09:26 PM
Hello,
i want to add my domain in download filenames. What is to change?
Thanks for your help!
Title: Add text to filename in Download an Zip-Download
Post by: Chris on June 11, 2003, 11:48:10 PM
Open download.php

At the very bottom, find this block of code:
Code: [Select]
if (!empty($file['file_data'])) {
  if (get_user_os() == "MAC") {
    header("Content-Type: application/x-unknown\n");
header("Content-Disposition: attachment; filename=\"".$file['file_name']."\"\n");
  }
  elseif (get_browser_info() == "MSIE") {
    $disposition = (!eregi("\.zip$", $file['file_name']) && $action != "zip" && $action != "lightbox") ? 'attachment' : 'inline';
    header("Content-Disposition: $disposition; filename=\"".$file['file_name']."\"\n");
    header("Content-Type: application/x-ms-download\n");
  }
  elseif (get_browser_info() == "OPERA") {
    header("Content-Disposition: attachment; filename=\"".$file['file_name']."\"\n");
    header("Content-Type: application/octetstream\n");
  }
  else {
    header("Content-Disposition: attachment; filename=\"".$file['file_name']."\"\n");
    header("Content-Type: application/octet-stream\n");
  }
  header("Content-Length: ".$file['file_size']."\n\n");
  echo $file['file_data'];
}


Replace it with:
Code: [Select]
if (!empty($file['file_data'])) {
  if (get_user_os() == "MAC") {
    header("Content-Type: application/x-unknown\n");
header("Content-Disposition: attachment; filename=\"".$_SERVER['HTTP_HOST']."_".$file['file_name']."\"\n");
  }
  elseif (get_browser_info() == "MSIE") {
    $disposition = (!eregi("\.zip$", $file['file_name']) && $action != "zip" && $action != "lightbox") ? 'attachment' : 'inline';
    header("Content-Disposition: $disposition; filename=\"".$_SERVER['HTTP_HOST']."_".$file['file_name']."\"\n");
    header("Content-Type: application/x-ms-download\n");
  }
  elseif (get_browser_info() == "OPERA") {
    header("Content-Disposition: attachment; filename=\"".$_SERVER['HTTP_HOST']."_".$file['file_name']."\"\n");
    header("Content-Type: application/octetstream\n");
  }
  else {
    header("Content-Disposition: attachment; filename=\"".$_SERVER['HTTP_HOST']."_".$file['file_name']."\"\n");
    header("Content-Type: application/octet-stream\n");
  }
  header("Content-Length: ".$file['file_size']."\n\n");
  echo $file['file_data'];
}


The names of all downloaded files will begin with "domain.com_"
Title: Add text to filename in Download an Zip-Download
Post by: Fred on June 12, 2003, 02:36:50 AM
Best thanks.
One question, can it be realised like "name_(domain.com).jpg"?
Title: Add text to filename in Download an Zip-Download
Post by: Chris on June 12, 2003, 02:45:43 AM
That's not so easy to do because $file['file_name'] stores "name.jpg" and you wouldn't want "name.jpg_(domain.com)".  Besides, if someone downloads 10 images and then views them in a file manager, like windows explorer, they will all be grouped together since they start with the same prefix.  This would make it easy to spot them amongst 100 other files in the same directory.

My advice would be to find all the places in download.php where $file_name is used and make adjustments as needed.  This is hard because if the file is a remote file, retrieved via remote URL, you have to manually parse the name.  It's also possible that some of those files might not have a file name extension.  Good luck.
Title: Add text to filename in Download an Zip-Download
Post by: V@no on June 12, 2003, 02:58:17 AM
try this:
replace all
Code: [Select]
$_SERVER['HTTP_HOST']."_".$file['file_name']
with:
Code: [Select]
substr($file['file_name'],0,(strlen($file['file_name'])-strlen(strrchr($file['file_name'],"."))))."_(".$_SERVER['HTTP_HOST'].").".substr(strrchr($file['file_name'],"."), 1)
Title: Add text to filename in Download an Zip-Download
Post by: Fred on June 12, 2003, 03:15:14 AM
Genius, whoho!
Still one Question: Why is before the first *dot* this: "[1]" (without "")?
Title: Add text to filename in Download an Zip-Download
Post by: V@no on June 12, 2003, 03:19:00 AM
I think IE browser does it...dont know why though
Title: Add text to filename in Download an Zip-Download
Post by: Chris on June 12, 2003, 03:29:14 AM
V@no's right, it's IE specific.  This doesn't happen with other browsers.  Chalk up another one for Microsoft not playing by accepted rules of conduct.
Title: Add text to filename in Download an Zip-Download
Post by: flamer on June 14, 2003, 01:26:37 PM
This is just want I want, Although I'm completeley useless with PHP.

What parts do I change to make the download filename show:

{site_name}_filename.zip

instead of www[1].domain.com_filename.zip ?

Thanks
Title: Add text to filename in Download an Zip-Download
Post by: V@no on June 14, 2003, 10:25:41 PM
Quote from: flamer
This is just want I want, Although I'm completeley useless with PHP.

What parts do I change to make the download filename show:

{site_name}_filename.zip

instead of www[1].domain.com_filename.zip ?

Thanks
I think the only fix for that is switch to another browser, other then IE... :?
Title: Add text to filename in Download an Zip-Download
Post by: flamer on June 15, 2003, 11:55:17 AM
Sorry, its not the fact that the [1] is in the filename I don't care about that.

I have a different domain name to my {site_name} and instead of adding domain I would like site name added or maybe some different custom text at a later date.
Title: Add text to filename in Download an Zip-Download
Post by: V@no on June 15, 2003, 03:38:36 PM
just change:
Code: [Select]
".$_SERVER['HTTP_HOST']."with:
Code: [Select]
blah_blah_blah
Title: Add text to filename in Download an Zip-Download
Post by: flamer on June 15, 2003, 04:20:18 PM
Quote from: V@no
just change:
Code: [Select]
".$_SERVER['HTTP_HOST']."with:
Code: [Select]
blah_blah_blah


Thanks...
Title: Add text to filename in Download an Zip-Download
Post by: Chris on June 16, 2003, 03:33:26 PM
You can also try:
Code: [Select]
".$config['site_name']."