Author Topic: Add text to filename in Download an Zip-Download  (Read 13470 times)

0 Members and 1 Guest are viewing this topic.

Offline Fred

  • Newbie
  • *
  • Posts: 29
    • View Profile
Add text to filename in Download an Zip-Download
« 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!

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Add text to filename in Download an Zip-Download
« Reply #1 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_"

Offline Fred

  • Newbie
  • *
  • Posts: 29
    • View Profile
Add text to filename in Download an Zip-Download
« Reply #2 on: June 12, 2003, 02:36:50 AM »
Best thanks.
One question, can it be realised like "name_(domain.com).jpg"?

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Add text to filename in Download an Zip-Download
« Reply #3 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.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Add text to filename in Download an Zip-Download
« Reply #4 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)
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 Fred

  • Newbie
  • *
  • Posts: 29
    • View Profile
Add text to filename in Download an Zip-Download
« Reply #5 on: June 12, 2003, 03:15:14 AM »
Genius, whoho!
Still one Question: Why is before the first *dot* this: "[1]" (without "")?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Add text to filename in Download an Zip-Download
« Reply #6 on: June 12, 2003, 03:19:00 AM »
I think IE browser does it...dont know why though
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
Add text to filename in Download an Zip-Download
« Reply #7 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.

Offline flamer

  • Pre-Newbie
  • Posts: 4
    • View Profile
    • http://www.meldrew.org
Add text to filename in Download an Zip-Download
« Reply #8 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

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Add text to filename in Download an Zip-Download
« Reply #9 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... :?
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 flamer

  • Pre-Newbie
  • Posts: 4
    • View Profile
    • http://www.meldrew.org
Add text to filename in Download an Zip-Download
« Reply #10 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.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Add text to filename in Download an Zip-Download
« Reply #11 on: June 15, 2003, 03:38:36 PM »
just change:
Code: [Select]
".$_SERVER['HTTP_HOST']."with:
Code: [Select]
blah_blah_blah
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 flamer

  • Pre-Newbie
  • Posts: 4
    • View Profile
    • http://www.meldrew.org
Add text to filename in Download an Zip-Download
« Reply #12 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...

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Add text to filename in Download an Zip-Download
« Reply #13 on: June 16, 2003, 03:33:26 PM »
You can also try:
Code: [Select]
".$config['site_name']."