_file_resource_retrieve

  1. services
    1. 7.3
    2. 6.3
Versions
6.3 _file_resource_retrieve($fid, $file_contents)
7.3 _file_resource_retrieve($fid, $include_file_contents, $get_image_style)

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

Code

resources/file_resource.inc, line 238

<?php
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) {
      foreach (image_styles() as $style) {
        $style_name = $style['name'];
        $file->image_styles[$style_name] = image_style_url($style_name, $file->uri);
      }
    }
    return $file;
  }
}
?>