Inicio › API reference ›
hook_file_download
hooks/core.php, line 501
- Versions
- hooks
hook_file_download($filepath)
Control access to private file downloads and specify HTTP headers.
This hook allows modules enforce permisisons on file downloads when the private file download method is selected. Modules can also provide headers to specify information like the file's name or MIME type.
Parameters
$filepath String of the file's path.
Valor de retorno
If the user does not have permission to access the file, return -1. If the user has permission, return an array with the appropriate headers. If the file is not controlled by the current module, the return value should be NULL.
Código
<?php
function hook_file_download($filepath) {
// Check if the file is controlled by the current module.
if ($filemime = db_result(db_query("SELECT filemime FROM {fileupload} WHERE filepath = '%s'", file_create_path($filepath)))) {
if (user_access('access content')) {
return array('Content-type:' . $filemime);
}
else {
return -1;
}
}
}
?> 
Comentarios recientes
hace 17 horas 50 mins
hace 1 día 10 horas
hace 1 semana 21 horas
hace 14 semanas 4 días
hace 19 semanas 19 horas
hace 20 semanas 2 días
hace 20 semanas 5 días
hace 20 semanas 5 días
hace 21 semanas 2 días
hace 22 semanas 1 día