function _file_resource_retrieve in Services 7.3
Same name and namespace in other branches
- 6.3 resources/file_resource.inc \_file_resource_retrieve()
Get a given file
Parameters
$fid: Number. File ID
$include_file_contents: Bool Whether or not to include the base64_encoded version of the file.
$get_image_style: Bool Whether or not to provide image style paths.
Return value
The file
1 call to _file_resource_retrieve()
- _node_resource_load_node_files in resources/
node_resource.inc - Generates an array of base64 encoded files attached to a node
1 string reference to '_file_resource_retrieve'
- _file_resource_definition in resources/
file_resource.inc - THERE SHOULD BE NO UPDATE!!! Drupal doesn't allow updating or replacing a file in the files table. If you need to, create a new file and remove the old file.
File
- resources/
file_resource.inc, line 277 - File resource.
Code
function _file_resource_retrieve($fid, $include_file_contents, $get_image_style) {
if ($file = file_load($fid)) {
$filepath = $file->uri;
// Convert the uri to the external url path provided by the stream wrapper.
$file->uri_full = file_create_url($file->uri);
// Provide a path in the form sample/test.txt.
$file->target_uri = file_uri_target($file->uri);
if ($include_file_contents) {
$file->file = base64_encode(file_get_contents(drupal_realpath($filepath)));
}
$file->image_styles = array();
// Add image style information if available.
if ($get_image_style && !empty($file->uri) && strpos($file->filemime, 'image') === 0) {
foreach (image_styles() as $style) {
$style_name = $style['name'];
$file->image_styles[$style_name] = image_style_url($style_name, $file->uri);
}
}
return $file;
}
}