You are here

function plupload_element_validate in Plupload integration 7

Same name and namespace in other branches
  1. 7.2 plupload.module \plupload_element_validate()

Element validation handler for a Plupload element.

1 string reference to 'plupload_element_validate'
plupload_element_info in ./plupload.module
Implements hook_element_info().

File

./plupload.module, line 228
Implementation of plupload.module.

Code

function plupload_element_validate($element, &$form_state) {
  foreach ($element['#value'] as $file_info) {

    // Here we create a $file object for a file that doesn't exist yet,
    // because saving the file to its destination is done in a submit handler.
    // Using tmp path will give validators access to the actual file on disk and
    // filesize information. We manually modify filename and mime to allow
    // extension checks.
    $file = plupload_file_uri_to_object($file_info['tmppath']);
    $destination = variable_get('file_default_scheme', 'public') . '://' . $file_info['name'];
    $destination = file_stream_wrapper_uri_normalize($destination);
    $file->filename = drupal_basename($destination);
    $file->filemime = file_get_mimetype($destination);
    foreach (file_validate($file, $element['#upload_validators']) as $error_message) {
      $message = t('The specified file %name could not be uploaded.', array(
        '%name' => $file->filename,
      ));
      form_error($element, $message . ' ' . $error_message);
    }
  }
}