Php 自定义codeingiter中文件上载的错误

Php 自定义codeingiter中文件上载的错误,php,codeigniter,file-upload,Php,Codeigniter,File Upload,我有一个来自两个文件上传:一个用于图像上传,另一个用于视频上传。现在的问题是,如果我上传视频或图像的无效文件类型,它会显示相同的错误 The filetype you are attempting to upload is not allowed. 我需要的是自定义错误,这样对于视频它就会像 不允许您尝试上载的视频。 我怎样才能做到这一点?我正在分享视频和图像的代码部分 查看页面代码: <tr> <td> <label for="video_type"

我有一个来自两个文件上传:一个用于图像上传,另一个用于视频上传。现在的问题是,如果我上传视频或图像的无效文件类型,它会显示相同的错误

The filetype you are attempting to upload is not allowed.
我需要的是自定义错误,这样对于视频它就会像

不允许您尝试上载的视频。

我怎样才能做到这一点?我正在分享视频和图像的代码部分

查看页面代码:

<tr>
  <td>
    <label for="video_type">Video Genre <span class="required">*</span></label>
  </td>
  <td>
    <?php 
    $array['']="Select";
    foreach($genre as $row)
    {
      $array[$row->id] = $row->genre;
    }
    echo form_dropdown('video_type',$array, set_value('video_type'));
    ?>
  </td>
  <td>
    <?php echo form_error('video_type'); ?>
  </td>
</tr>
<tr>
  <td>
    <label for="uploader_id">Upload Video <span class="required">*</span></label>
  </td>
  <td>
    <input type="file" name="video"  class="input" value="<?php echo set_value('video'); ?>" />
  </td>
  <td>
    <?php echo form_error('video'); ?>
  </td>
</tr>
function index()
{   
  $data['dropdown'] = lang_dropdown();  // multilanguage dropdown list
  $data['language']=$this->session->userdata('site_language');
  $userid=$this->tank_auth->get_user_id();

  if (empty($_FILES['thumb_image']['name']))
  {
    $this->form_validation->set_rules('thumb_image', 'Thumb Image', 'required|max_length[255]');  
  }

  if (empty($_FILES['video']['name']))
  {
    $this->form_validation->set_rules('video', 'Video', 'required');
  }     
  $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
  $data['page']='video/upload';

  if ($this->form_validation->run() == FALSE) // validation hasn't been passed
  {
    $this->load->view('layout/template',$data);
  }
  else // passed validation proceed to post success logic
  {
    $file=$_FILES['video']['name'];
    $thumbfile=$_FILES['thumb_image']['name'];
    $form_data = array(                
                'videolink' => time().$file,
                'videothumbnail' => time().$thumbfile,
                'uploaderid' => $userid,
                'uploaderid' => set_value('1'),
    );
    $config['upload_path'] = './secure/';
    $config['allowed_types'] = 'mpeg|mp4|mpg|mpe|qt|mov|avi|movie|wmv|flv|3gp|mkv|dv|m4u|m4v|mxu|rv';
    $extn = end(explode(".", $_FILES['video']['name']));
    $config['file_name'] = time().$_FILES['video']['name'].'.'.$extn;    
    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    $data['upload_data'] = '';

    if (!$this->upload->do_upload('video')) 
    {
      $data['msg'] = $this->upload->display_errors();
      $this->load->view('layout/template',$data);
    } 
    else 
    { 
      $data['upload_data'] = $this->upload->data();

      if($_FILES['thumb_image']['name']!="")
      {
        $config1['upload_path'] = './secure/';        
        $ext = end(explode(".", $_FILES['thumb_image']['name']));
        $config1['file_name'] = time().$_FILES['thumb_image']['name'].'.'.$ext;        
        $config1['allowed_types'] = 'jpg|png|jpeg|gif|bmp|jpe|tiff|tif';
        $this->load->library('upload', $config1);
        $this->upload->initialize($config1);

        if (!$this->upload->do_upload('thumb_image')) 
        {
          $data['msg'] = $this->upload->display_errors();
          $this->load->view('layout/template',$data);
        }        
      }

      if ($this->Video_model->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db
      {
        $data['successmsg']="Successfully uploaded the video";
      }
      else
      {
        echo 'An error occurred saving your information. Please try again later';
      }

      $this->form_validation->unset_field_data();
      $this->load->view('layout/template',$data);
    }
  }
}

视频类型*
上传视频*
试试这个

if (empty($_FILES['video']['name']))
  {
    $this->form_validation->set_message('required', 'video name incorrect'); //put this line above this statement
    $this->form_validation->set_rules('video', 'Video', 'required');
  } 

尝试这个答案,并按照评论进行操作:我已经尝试过了。但对我无效。请检查此链接