function field_file_load in FileField 6.2
Same name and namespace in other branches
- 6.3 field_file.inc \field_file_load()
Load a file object from the database.
Parameters
$fid: A numeric file id or string containing the file path.
$reset: Whether to reset the internal file_load cache.
2 calls to field_file_load()
- filefield_field in ./
filefield.module - Implementation of CCK's hook_field().
- filefield_widget in ./
filefield.widget.inc - Implementation of hook_widget() - the one in filefield.module is just there to include this one on demand.
File
- ./
field_file.inc, line 16 - Common functionality for file handling CCK field modules.
Code
function field_file_load($fid, $reset = NULL) {
// Reset internal cache.
if (isset($reset)) {
_field_file_cache(NULL, TRUE);
}
if (empty($fid)) {
return array();
}
$files = _field_file_cache();
// Serve file from internal cache if available.
if (empty($files[$fid])) {
if (is_numeric($fid)) {
$file = db_fetch_object(db_query('SELECT f.* FROM {files} f WHERE f.fid = %d', $fid));
}
else {
$file = db_fetch_object(db_query("SELECT f.* FROM {files} f WHERE f.filepath = '%s'", $fid));
}
if (!$file) {
return array();
}
foreach (module_implements('file_load') as $module) {
$function = $module . '_file_load';
$function($file);
}
// Cache the fully loaded file for later reusability.
$files = _field_file_cache($file);
}
// Cast to array for field. hook_file() expects objects as well as
// core file functions.
return (array) $files[$fid];
}