You are here

function upload_file_download in Drupal 6

Same name and namespace in other branches
  1. 4 modules/upload.module \upload_file_download()
  2. 5 modules/upload/upload.module \upload_file_download()

Implementation of hook_file_download().

File

modules/upload/upload.module, line 146
File-handling and attaching files to nodes.

Code

function upload_file_download($filepath) {
  $filepath = file_create_path($filepath);
  $result = db_query("SELECT f.*, u.nid FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid WHERE filepath = '%s'", $filepath);
  while ($file = db_fetch_object($result)) {
    if ($filepath !== $file->filepath) {

      // Since some database servers sometimes use a case-insensitive
      // comparison by default, double check that the filename is an exact
      // match.
      continue;
    }
    if (user_access('view uploaded files') && ($node = node_load($file->nid)) && node_access('view', $node)) {
      return array(
        'Content-Type: ' . $file->filemime,
        'Content-Length: ' . $file->filesize,
      );
    }
    else {
      return -1;
    }
  }
}