Hello!
Ithe Private Method has a big problem during file download process, it renames the file name. (ref. http://drupal.org/node/145872)

Example:

File upload = ubuntu.rar
File download = x3n4xt4us

That's because the HEADER is not passed correctly.

These are some modules that I fixed in order to solve this problem and I hope that they will be adopted in future.

Bye.

-------------------------
Module: UPLOAD
File:   upload.module
--------------------------

function upload_file_download($file) {
  $file = file_create_path($file);
  $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file);
  if ($file = db_fetch_object($result)) {
    if (user_access('view uploaded files')) {
      $node = node_load($file->nid);
      if (node_access('view', $node)) {
        $type = mime_header_encode($file->filemime);
        return array(
          'Content-Type: '. $type,
//tarabas: add filename to header
          'Content-Disposition: attachment; filename='.$file->filename,
          'Content-Length: '. $file->filesize,
        );
      }
      else {
        return -1;
      }
    }
    else {
      return -1;
    }
  }
}

--------------------------------------
MODULE: project_issue
FILE:   project_issue.module
--------------------------------------

function project_issue_file_download($file) {
  $file = file_create_path($file);
//tarabas: add filename to header
 $file_info = db_fetch_object(db_query("SELECT nid, file_path, file_mime, file_size FROM {project_issues} WHERE file_path = '%s'", $file));
  if (!$file_info) {
//tarabas: add filename to header
 $file_info = db_fetch_object(db_query("SELECT nid, file_path, file_mime, file_size FROM {project_comments} WHERE file_path = '%s'", $file));
  }
  if ($file_info) {
    if (user_access('access project issues')) {
      $node = node_load($file_info->nid);
      if (node_access('view', $node)) {
        $type = mime_header_encode($file_info->file_mime);
        return array(
          'Content-type: '. $type,
//tarabas: add filename to header
          'Content-Disposition: attachment; filename='.basename($file_info->file_path),
          'Content-length: '. $file_info->file_size,
        );
      }
      else {
         return -1;
      }
    }
    else {
      return -1;
    }
  }
}

----------------------------
Module: comment_upload
File:   comment_upload.module
-----------------------------

function comment_upload_file_download($file) {
  $file = file_create_path($file);
  $result = db_query("SELECT f.* FROM {comment_upload_files} f WHERE filepath = '%s'", $file);
  if ($file = db_fetch_object($result)) {
    if (user_access('view uploaded files')) {
      $node = node_load($file->nid);
      if (node_access('view', $node)) {
        $name = mime_header_encode($file->filename);
        $type = mime_header_encode($file->filemime);
        return array(
          'Content-Type: '. $type .'; name='. $name,
//tarabas: add filename to header
          'Content-Disposition: attachment; filename='.$file->filename,
          'Content-Length: '. $file->filesize,
          'Expires: 0', 'Pragma: cache', 'Cache-Control: private',
        );
      }
      else {
        return -1;
      }
    }
    else {
      return -1;
    }
  }
}

Comments

ffranz’s picture

thx :) ... perfect!

jvieille’s picture

Would it be possible that this problem was still pending?
http://drupal.org/node/395428

Is Private Upload faulty too?

JV