You are here

function file_export_alter in Default Content 7

Same name and namespace in other branches
  1. 7.2 plugins/file.inc \file_export_alter()

Prepares file field for export to code

File

plugins/file.inc, line 15

Code

function file_export_alter(&$node) {
  $fields = get_file_fields();
  foreach ($fields as $field_name => $field) {
    if (isset($node->{$field_name})) {
      foreach ($node->{$field_name} as $lang => $items) {
        foreach ($items as $key => $item) {
          $imgfile = drupal_realpath($item['uri']);
          if ($imgfile && ($handle = fopen($imgfile, 'rb')) && filesize($imgfile) > 0) {
            $imgbinary = fread($handle, filesize($imgfile));
            $node->{$field_name}[$lang][$key]['image'] = base64_encode($imgbinary);
          }
          $filename = $node->{$field_name}[$lang][$key]['filename'];
          $node->{$field_name}[$lang][$key]['uri'] = 'public://' . $filename;
          unset($node->{$field_name}[$lang][$key]['fid']);
          unset($node->{$field_name}[$lang][$key]['uid']);
          unset($node->{$field_name}[$lang][$key]['timestamp']);
        }
      }
    }
  }
}