function image_file_download in Image 5
Same name and namespace in other branches
- 5.2 image.module \image_file_download()
- 6 image.module \image_file_download()
Implementation of hook_file_download().
Note that in Drupal 5, the upload.module's hook_file_download() checks its permissions for all files in the {files} table. We store our file information in {files} if private files transfers are selected and the upload.module is enabled, users will the 'view uploaded files'permission to view images.
1 call to image_file_download()
- image_fetch in ./
image.module - Fetches an image file, allows "shorthand" image urls such of the form: image/view/$nid/$label (e.g. image/view/25/thumbnail or image/view/14)
File
- ./
image.module, line 382
Code
function image_file_download($filename) {
$filepath = file_create_path($filename);
$result = db_query("SELECT f.nid, f.filename, f.filesize, f.filemime FROM {files} f WHERE f.filepath = '%s'", $filepath);
if ($file = db_fetch_object($result)) {
$node = node_load(array(
'type' => 'image',
'nid' => $file->nid,
));
if ($node) {
if (node_access('view', $node)) {
// The user either needs to have 'view original images' permission or
// the path must be listed for something other than the node's original
// size. This will be the case when the orignal is smaller than a
// derivative size.
$images = (array) $node->images;
unset($images[IMAGE_ORIGINAL]);
if (user_access('view original images') || in_array($filepath, $images)) {
return array(
'Content-Type: ' . mime_header_encode($file->filemime),
'Content-Length: ' . (int) $file->filesize,
);
}
}
return -1;
}
}
}