function upload_file_download in Drupal 5
Same name and namespace in other branches
- 4 modules/upload.module \upload_file_download()
- 6 modules/upload/upload.module \upload_file_download()
File
- modules/
upload/ upload.module, line 260 - File-handling and attaching files to nodes.
Code
function upload_file_download($file) {
$filepath = file_create_path($file);
$result = db_query("SELECT f.* FROM {files} f 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);
if (node_access('view', $node)) {
$type = mime_header_encode($file->filemime);
return array(
'Content-Type: ' . $type,
'Content-Length: ' . $file->filesize,
);
}
}
return -1;
}
}