You are here

function dynamic_banner_upload_image_validate in Dynamic Banner 7

Same name and namespace in other branches
  1. 7.2 dynamic_banner.module \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 includes/callbacks.inc
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

includes/callbacks.inc, line 535
Dynamic Banner Admin Pages and various other functions to make them work Most of the code in this file was derived from path module

Code

function dynamic_banner_upload_image_validate($form, &$form_state) {

  // This is not needed, I use this to use the same validate function
  // for several fields.

  /*$file = file_save_upload($form['values']['image'], array(
      'file_validate_is_image'   => array(),
      'file_validate_extensions' => array('png gif jpg jpeg'),
    ));*/
  if (isset($form_state['values']['image']) && $form_state['values']['image'] != 0) {
    $file = file_load($form_state['values']['image']);
    if ($file) {

      // Get the image info to get the correct extension for the uploaded file.

      /*$info = image_get_info($file->filepath);
        if (file_move($file, 'destination/filename'. $info['extension'], FILE_EXISTS_REPLACE)) {
          // Mark the file for permanent storage.
          file_set_status($file, FILE_STATUS_PERMANENT);
          // Update the files table.
          drupal_write_record('files', $file, 'fid');*/

      // 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_set_error($form_state['values']['image'], t('Failed to write the uploaded file to the folder.'));
    }
  }
  elseif ($form_state['values']['image'] == 0) {
    dynamic_banner_image_delete($form_state['values']['oldimagefid']);
  }
}