You are here

function upload_file_download in Drupal 4

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

File

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

Code

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)) {
        $name = mime_header_encode($file->filename);
        $type = mime_header_encode($file->filemime);
        return array(
          'Content-Type: ' . $type . '; name=' . $name,
          'Content-Length: ' . $file->filesize,
          'Expires: 0',
          'Pragma: cache',
          'Cache-Control: private',
        );
      }
      else {
        return -1;
      }
    }
    else {
      return -1;
    }
  }
}