You are here

function file_entity_generate_file in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 file_entity.devel_generate.inc \file_entity_generate_file()

Generate file function for file_entity.

1 call to file_entity_generate_file()
file_entity_generate_file_batch_generate in ./file_entity.devel_generate.inc
Implements hook_generate_file_batch_generate() using Devel generate api.

File

./file_entity.devel_generate.inc, line 152
Devel generate integration for the File Entity module.

Code

function file_entity_generate_file($file_type) {
  $type = file_type_load($file_type);
  $possible_extensions = file_type_get_valid_extensions($type);
  $image_extensions = array(
    'png',
    'gif',
    'jpg',
    'jpeg',
  );
  if (array_intersect($possible_extensions, $image_extensions)) {
    $extension = array_rand(array_flip($image_extensions));
    module_load_include('inc', 'devel_generate', 'image.devel_generate');
    $path = devel_generate_image($extension, '100x100', '1500x1500');
  }
  else {
    $extension = array_rand(array_flip($possible_extensions));
    module_load_include('inc', 'devel_generate', 'file.devel_generate');
    $path = devel_generate_textfile(mt_rand(1024, 102400));
  }
  $uri = file_entity_generate_unique_uri($extension);
  $dir = dirname($uri);
  if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
    return FALSE;
  }
  if (file_unmanaged_move($path, $uri)) {
    return $uri;
  }
  return FALSE;
}