Truncates filenames ending in .exe

grand_master_v - June 20, 2006 - 23:58
Project:Disk Node
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

When linking a file to a page with disk node it produces a download link at the bottom of the page. I find that I can download the file with no problems using firefox but using IE 6 it truncates the filename to whatever comes before the first dot " . " in the filename. This cuts off the file extension making the user have to rename the file.

#1

grand_master_v - June 21, 2006 - 00:47
Title:Download link cuts off file extension in IE 6» Only cuts off files ending in .exe

I tested out a .pdf and .dmg and they both work fine its only the .exe files that are getting truncated.

#2

grand_master_v - June 21, 2006 - 21:55
Title:Only cuts off files ending in .exe» Truncates filenames ending in .exe

Found this on the microsoft site related to IIS and IE 6
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B840387

I cant seem to disable the gzip compression for the files in drupal though.

#3

grand_master_v - June 30, 2006 - 19:11

Gzip is not the problem.

Just looks like IE is handling the file wrong.

#4

gocarts - November 8, 2006 - 15:09

I am experiencing the same problem and came across the following:

http://support.microsoft.com/kb/221805

Which describes a bug in IE v4, that was fixed in IE v5, but seems to have reappeared in IE v6 whereby urls with .exe extensions followed by arguments (eg. somewhere/foo.exe?anything) are truncated (eg. somewhere/foo).

My suggested fix in disknode.inc is as follows:

function _disknode_get($fid, $fname="") {
  $fid = intval($fid);
  $result = db_fetch_object(db_query("SELECT f.filepath, d.counter FROM {files} f LEFT JOIN {downloads} d ON f.fid = d.fid WHERE f.fid = %d", $fid));
  if (!$result)
  {
    drupal_not_found();
    return;
  }
  if (is_numeric($result->counter)) {
    db_query("UPDATE {downloads} SET counter = counter + 1 WHERE fid=%d", $fid);
  }
  else {
    db_query("INSERT INTO {downloads} (fid, counter) VALUES (%d, 1)", $fid);
  }
  $url = file_create_url(str_replace("%2F", "/", rawurlencode($result->filepath)));
// Remove arguments after file to avoid IE v6 truncation of .exe files.
//  if (strstr($url, "?") === false) $url .= "?";
//  else $url .= "&";
//  $url .= "download";
  header("Location: ".$url);
  exit();
}

Could someone confirm whether this solution is correct?

An alternate solution offered in the support link would be to append an extra arg containing the file name as follows:

function _disknode_get($fid, $fname="") {
  $fid = intval($fid);
// Extract f.filename to append to url as arg, see below 
  $result = db_fetch_object(db_query("SELECT f.filepath, f.filename, d.counter FROM {files} f LEFT JOIN {downloads} d ON f.fid = d.fid WHERE f.fid = %d", $fid));
  if (!$result)
  {
    drupal_not_found();
    return;
  }
  if (is_numeric($result->counter)) {
    db_query("UPDATE {downloads} SET counter = counter + 1 WHERE fid=%d", $fid);
  }
  else {
    db_query("INSERT INTO {downloads} (fid, counter) VALUES (%d, 1)", $fid);
  }
  $url = file_create_url(str_replace("%2F", "/", rawurlencode($result->filepath)));
  if (strstr($url, "?") === false) $url .= "?";
  else $url .= "&";
  $url .= "download";
// Append extra arg to work around IE v6 bug with exe extensions
  $url .="&filename=".$result->filename;
  header("Location: ".$url);
  exit();
}

Which is preferred?

#5

macfly2500 - October 10, 2007 - 03:17
Version:4.7.x-1.x-dev» 5.x-1.x-dev

Hi,

Work fine for me removing arguments after filename:
...files/myfile.exe?download <---- removed ?download from url

How is objective of this args in url?

Thanks

#6

piano1113 - September 18, 2008 - 07:36

I am using version 6.4 and having the same problems. It is a software support website with a demo download (an exe file). I have the file as an attachment in a forum at the moment. When attempting to download with FF, IE, or Safari the filename and extension is changed. I have found almost no info regarding this issue. Has anyone else experienced this and/or solved the problem?

I am using Forum Access, Node Privacy by Role, and ACL modules. I have file uploads set to Private.

The proposed solutions above are about disknode.inc... This was/is a module? I see file.inc in the includes folder in version 6.4 and it seems to be the file to edit but I have had no luck thus far. I have working on this for many hours now.

I am just getting started with drupal. I have a fair amount of PHP knowledge. I am working on a solution similar to the above earlier proposed solutions and trying to find the functions to edit.

Please let me know if I am missing something, headed the wrong direction, or have overlooked a previously posted fix.

#7

Ectar - September 18, 2008 - 14:00

Cannot reproduce.

Here is the link to he website which hosts disknode - http://mobilemodding.info/test-exe you can download exe file properly from any browser.

 
 

Drupal is a registered trademark of Dries Buytaert.