You are here

function RealisticDummyContentAttribute::FileSave in Realistic Dummy Content 7

Return a file object.

Parameters

$file: The original file, a RealisticDummyContentFileGroup object.

Return value

A file object.

Throws

Exception.

1 call to RealisticDummyContentAttribute::FileSave()
RealisticDummyContentAttribute::ImageSave in api/includes/RealisticDummyContentAttribute.inc
Return an image file object if possible.

File

api/includes/RealisticDummyContentAttribute.inc, line 313
Define RealisticDummyContentAttribute autoload class.

Class

RealisticDummyContentAttribute
Represents either a field or a property for an entity.

Code

function FileSave($file) {
  $drupal_file = $file
    ->GetFile();
  if (!$drupal_file) {
    throw new RealisticDummyContentException('Please check if the file exists before attempting to save it');
  }
  $uri = $drupal_file->uri;

  //$random = md5($uri) . rand(1000000000, 9999999999);

  // DO NOT RENAME FOR TESTING
  $random = $file
    ->GetRadical();
  $drupal_file = $this
    ->env()
    ->file_save_data($file
    ->Value(), 'public://dummyfile' . $random . '.' . $file
    ->GetRadicalExtension());
  $drupal_file->uid = $this
    ->GetUid();
  $return = file_save($drupal_file);
  return $return;
}