You are here

function _emthumb_file_upload in Embedded Media Field 6.3

Same name and namespace in other branches
  1. 6.2 contrib/emthumb/emthumb.module \_emthumb_file_upload()
2 calls to _emthumb_file_upload()
emthumb_widget_element_process in contrib/emthumb/emthumb.module
Process our emthumb element.
emthumb_widget_upload_button_submit in contrib/emthumb/emthumb.module

File

contrib/emthumb/emthumb.module, line 279
Allows for custom thumbnail overrides to Embedded Media Field.

Code

function _emthumb_file_upload(&$form_state, $field_name, $field, $delta, $upload_op, $from_process = FALSE) {
  $limits = array(
    'extensions' => 'jpg jpeg gif png',
    'file_size' => 0,
    'user_size' => 0,
    'resolution' => 0,
  );
  $validators = array(
    'file_validate_extensions' => array(
      $limits['extensions'],
    ),
    'file_validate_image_resolution' => array(
      $limits['resolution'],
    ),
    'file_validate_size' => array(
      $limits['file_size'],
      $limits['user_size'],
    ),
  );
  $filename = $source = $field_name . '_' . $delta . '_file';
  if ($file = file_save_upload($filename, $validators, file_create_path($field['widget']['emimport_image_path']), FILE_EXISTS_RENAME)) {
    $file = (array) $file;
    if (strpos($file['filemime'], 'image') !== FALSE) {
      $file = _emthumb_scale_image($file, $field['widget']['emthumb_max_resolution']);

      // Store the current file so it's available in a later form_get_cache.
      $form_state['storage']['emthumb'][$upload_op] = $file;
    }
    else {
      form_set_error('', t("The file you uploaded was not recognized as an image. Please upload a different image type."));
    }
  }
  else {
    if (!$from_process) {
      form_set_error('', t("There was an error uploading your file."));
    }
  }
  $file = $file ? $file : array();
  return $file;
}