function file_aliases_load_fid in File Aliases 7
Same name and namespace in other branches
- 5 file_aliases.module \file_aliases_load_fid()
- 6 file_aliases.module \file_aliases_load_fid()
Menu callback; File Alias callback.
Parameters
$fid:
1 string reference to 'file_aliases_load_fid'
- file_aliases_menu in ./
file_aliases.module - Implements hook_menu().
File
- ./
file_aliases.module, line 109 - Contains core functions for the File Aliases module.
Code
function file_aliases_load_fid($fid) {
if (request_uri() == base_path() . "file_aliases/{$fid}") {
drupal_not_found();
exit;
}
/** @var DatabaseStatementBase $query */
$query = db_select('file_managed', 'f')
->fields('f', array(
'filemime',
'filesize',
'uri',
))
->condition('fid', $fid)
->execute();
$results = $query
->fetchAll();
$result = current($results);
if (!$result) {
return;
}
// Render Image Style preset if applicable.
$uri = explode('?', request_uri());
if (isset($uri[1]) && strpos($result->filemime, 'image') === 0) {
if (defined('IMAGE_DERIVATIVE_TOKEN')) {
list($uri[1], ) = explode('&', $uri[1]);
}
$image_style = $uri[1];
$styles = image_styles();
if (isset($styles[$image_style])) {
$arguments = array_merge(array(
image_style_load($image_style),
file_uri_scheme($result->uri),
), explode('/', str_replace(file_uri_scheme($result->uri) . '://', '', $result->uri)));
call_user_func_array('image_style_deliver', $arguments);
}
}
if (!$result || !is_object($result)) {
return;
}
elseif (file_uri_scheme($result->uri) == 'private') {
$file = explode('://', $result->uri);
file_download($file[0], $file[1]);
}
else {
drupal_add_http_header('Cache-Control', 'public');
drupal_add_http_header('Content-Length', $result->filesize);
drupal_add_http_header('Content-Type', $result->filemime);
readfile($result->uri);
}
}