You are here

function filefield_filefield_filesize_restrictions in FileField 6.2

Implementation of hook_filefield_filesize_restrictions(): Specify how large a newly uploaded file may be, in bytes. (The smallest size of all hook implementations will be applied in the end).

File

./filefield.widget.inc, line 415
FileField: Defines a CCK file field type.

Code

function filefield_filefield_filesize_restrictions($field, $widget, $existing_files) {
  $filesize_restrictions = array(
    file_upload_max_size(),
  );

  // Maximum file size for each file separately.
  if (!empty($widget['max_filesize_per_file'])) {
    $filesize_restrictions[] = parse_size($widget['max_filesize_per_file']);
  }

  // Maximum file size for all files in the node (for this field).
  if (!empty($widget['max_filesize_per_node'])) {
    $allowed_total_size = parse_size($widget['max_filesize_per_node']);
    $total_size = 0;
    foreach ($existing_files as $delta => $file) {
      if (!empty($file->filesize)) {
        $total_size += $file->filesize;
      }
    }
    if (!empty($total_size)) {
      $filesize_restrictions[] = $allowed_total_size - $total_size;
    }
  }
  return $filesize_restrictions;
}