function field_file_load in FileField 6.3
Same name and namespace in other branches
- 6.2 field_file.inc \field_file_load()
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.
9 calls to field_file_load()
- FileFieldTestCase::assertFileEntryExists in tests/
filefield.test - Assert that a file exists in the database.
- FileFieldTestCase::assertFileEntryNotExists in tests/
filefield.test - Assert that a file does not exist in the database.
- filefield_field_load in ./
filefield_field.inc - Implementation of CCK's hook_field($op = 'load').
- filefield_field_sanitize in ./
filefield_field.inc - Implementation of CCK's hook_field($op = 'sanitize').
- filefield_widget_process in ./
filefield_widget.inc - An element #process callback for the filefield_widget field type.
File
- ./
field_file.inc, line 17 - 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(
'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) {
if ($module != 'field') {
$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;
}