You are here

function _filefield_generate_textfile in FileField 6.3

Private function for generating a random text file.

1 call to _filefield_generate_textfile()
_filefield_generate_file in ./filefield.devel.inc
Generate an image based on the properties of a field.

File

./filefield.devel.inc, line 61
Utility functions for generating FileField content. Note that image generation support requires the GD toolkit.

Code

function _filefield_generate_textfile($filesize = 1024) {
  static $filesizes = array();
  $temp_file = FALSE;
  if (isset($filesizes[$filesize])) {
    $temp_file = $filesizes[$filesize];
  }
  elseif ($temp_file = tempnam(file_directory_temp(), 'filefield_')) {
    file_move($temp_file, $temp_file . '.txt');
    $fp = fopen($temp_file, 'w');
    fwrite($fp, str_repeat('01', $filesize / 2));
    fclose($fp);
    $filesizes[$filesize] = $temp_file;
  }
  return $temp_file;
}