_node_resource_load_node_files

  1. services
    1. 7.3
    2. 6.3
Versions
7.3 _node_resource_load_node_files($nid, $include_file_contents, $get_image_style)
6.3 _node_resource_load_node_files($nid, $include_file_contents)

Generates an array of base64 encoded files attached to a node

Parameters

$nid Number. Node 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

Array. A list of all files from the given node

Code

resources/node_resource.inc, line 470

<?php
function _node_resource_load_node_files($nid, $include_file_contents, $get_image_style) {
  module_load_include('inc', 'services', 'resources/file_resource');
  $node = node_load($nid);

  // Hopefully theres another way to get a nodes fields that are a file, but this was the only way I could do it.
  $fields = field_info_fields();
  $files = array();

  // Loop through all of the fields on the site
  foreach ($fields as $key => $field) {
    //if we are a field type of file
    if ($field['type'] == 'image' || $field['type'] == 'file') {
      // If this field exists on our current node..
      if (isset($node->{$field['field_name']})) {
        // If there are items in the field...
        if (isset($node->{$field['field_name']}[LANGUAGE_NONE])) {
          // Grab the items given and attach them to the array.
          $node_file_field_items = $node->{$field['field_name']}[LANGUAGE_NONE];
          foreach ($node_file_field_items as $file) {
            $files[] = _file_resource_retrieve($file['fid'], $include_file_contents, $get_image_style);
          }
        }
      }
    }
  }

  return $files;
}
?>