You are here

function video_upload_manual_thumb in Video 6.5

Same name and namespace in other branches
  1. 6.4 video_widget.inc \video_upload_manual_thumb()

Handle saving of manual thumbs

1 call to video_upload_manual_thumb()
video_widget_process in ./video_widget.inc
Video_widget_process for API handlers for any video types.

File

./video_widget.inc, line 337
Common Video module widget functions

Code

function video_upload_manual_thumb(&$element) {
  $destination = video_thumb_path($element['#value']);
  if (!is_dir($destination)) {
    form_set_error('video_thumb_upload', t('The thumbnail image could not be uploaded. The destination %destination does not exist or is not writable by the server.', array(
      '%destination' => $destination,
    )));
    return;
  }
  $validators = array(
    'file_validate_is_image' => array(),
  );
  if (!($file = file_save_upload($element['#field_name'] . '_' . $element['#delta'] . '_thumbs', $validators, $destination))) {

    // No upload to save we hope... or file_save_upload() reported an error on its own.
    return;
  }

  // Remove old image (if any) & clean up database.
  $old_thumb = $element['data']['video_thumb']['#value'];
  if (!empty($old_thumb)) {
    if (file_delete($old_thumb)) {
      db_query('DELETE FROM {files} WHERE filepath=\'%s\'', $old_thumb);
    }
  }

  // Make the file permanent and store it in the form.
  file_set_status($file, FILE_STATUS_PERMANENT);
  $element['data']['video_thumb']['#value'] = $file->filepath;
}