field_file_load
- Versions
- 6
field_file_load($fid, $reset = NULL)
Load a file from the database.
Parameters
$fid A numeric file id or string containing the file path.
$reset Whether to reset the internal file_load cache.
Return value
A file array.
Code
contrib/filefield/field_file.inc, line 18
<?php
function field_file_load($fid, $reset = NULL) {
// Reset internal cache.
if (isset($reset)) {
_field_file_cache(NULL, TRUE);
}
if (empty($fid)) {
return array('fid' => 0, 'filepath' => '', 'filename' => '', 'filemime' => '', 'filesize' => 0);
}
$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) {
$file = (object) array('fid' => 0, 'filepath' => '', 'filename' => '', 'filemime' => '', 'filesize' => 0);
}
foreach (module_implements('file_load') as $module) {
$function = $module .'_file_load';
$function($file);
}
// Cache the fully loaded file for later use.
$files = _field_file_cache($file);
}
// Cast to an array for the field storage.
// Contrary to fields, hook_file() and core file functions expect objects.
return isset($files[$fid]) ? (array) $files[$fid] : FALSE;
}
?>


