You are here

function comment_upload_file_download in Comment Upload 6

Same name and namespace in other branches
  1. 5 comment_upload.module \comment_upload_file_download()

Implementation of hook_file_download().

File

./comment_upload.module, line 181
Provides file attachment functionality for comments.

Code

function comment_upload_file_download($filepath) {
  $filepath = file_create_path($filepath);
  $result = db_query("SELECT f.*, cu.nid FROM {files} f INNER JOIN {comment_upload} cu ON f.fid = cu.fid WHERE filepath = '%s'", $filepath);
  if ($file = db_fetch_object($result)) {
    if (user_access('view files uploaded to comments') && ($node = node_load($file->nid)) && node_access('view', $node)) {
      return array(
        'Content-Type: ' . mime_header_encode($file->filemime),
        'Content-Length: ' . $file->filesize,
      );
    }
    else {
      return -1;
    }
  }
}