You are here

function dynamic_banner_upload_image_validate in Dynamic Banner 7.2

Same name and namespace in other branches
  1. 7 includes/callbacks.inc \dynamic_banner_upload_image_validate()
  2. 8.x dynamic_banner.module \dynamic_banner_upload_image_validate()

Validate/submit handler used for handling image uploads

1 string reference to 'dynamic_banner_upload_image_validate'
dynamic_banner_admin_form in ./dynamic_banner.module
The main form dealing with dynamic banner There is now only one form for dynamic banner to deal with unlink in the d6 version

File

./dynamic_banner.module, line 717
Distributed under GNU GPL version 3

Code

function dynamic_banner_upload_image_validate($element, &$form_state) {
  if (!isset($element['#value']['fid']) || empty($element['#value']['fid'])) {
    form_error($element, t('Please Upload a Image'));
  }
  $file = file_load($element['#value']['fid']);
  if ($file) {

    // Get the image info to get the correct extension for the uploaded file.
    // Change status to permanent.
    $file->status = FILE_STATUS_PERMANENT;

    // When a module is managing a file, it must manage the usage count.
    // Here we increment the usage count with file_usage_add().
    file_usage_add($file, 'dynamic_banner', 'banner', 1);

    // Save the file again for permanent status
    file_save($file);
  }
  else {
    form_error($element, t('Failed to write the uploaded file to the folder.'));
  }
}