You are here

function _video_upload_validate in Video 5

Validate video file

1 call to _video_upload_validate()
video_upload_nodeapi in types/video_upload/video_upload.module
Implementation of hook_nodeapi()

File

types/video_upload/video_upload.module, line 393
Enable Uploaded videos support for video module.

Code

function _video_upload_validate(&$node) {

  //print 'validate';

  //print_r($node); die;
  if (!($node->new_file_uploaded || $node->new_video_upload_file_fid > 0 || $node->new_video_upload_file_fid > 0 || $node->current_video_upload_file_fid > 0)) {

    //
    form_set_error('video_upload_file', t('You have not provided any video file. Please upload one.<br />If you uploaded a video but the system did not received it, please check that it is smaller than') . ' ' . format_size(file_upload_max_size()) . '.');
  }
  else {
    if ($node->new_file_uploaded || $node->new_video_upload_file_fid > 0 || $node->new_video_upload_file_fid > 0) {
      if ($node->new_file_uploaded) {

        // only if the user oploaded a new file
        $file = $node->new_file_uploaded;
      }
      else {
        $file = _video_upload_get_file($node->new_video_upload_file_fid);
      }

      // let's check file extension
      $extensions = variable_get('video_upload_allowed_extensions', 'mov,flv,wmv');
      $regex = '/\\.(' . ereg_replace(',+', '|', preg_quote($extensions)) . ')$/i';
      if (!preg_match($regex, $file->filename)) {

        //set an error message and delete the the file
        form_set_error('audio', t('The selected file %name can not be uploaded, because it is only possible to upload files with the following extensions: %files-allowed.', array(
          '%name' => $file->filename,
          '%files-allowed' => $extensions,
        )));
        _video_upload_delete_file($file);
      }
    }
  }
}