代码点火器中的图像类型验证


Image Type Validation in codeigniter

我是Codeigniter的新手。处理表单中具有图像的表单验证。在 CodeIgniter 中使用模块 MVC 扩展。

对于上传图像,我发现了这个文件上传代码段

   $config['upload_path'] = './uploads/audio_files/';
   $config['allowed_types'] = 'gif|jpg|jpeg|png';
   $config['max_size']  = '2048';
   $this->load->library('upload', $config);
  if ( ! $this->upload->do_upload($file_name))
   {
    $error = array('error' => $this->upload->display_errors());
    $file1 = '';
   }
 else
   {
    $upload_data =  $this->upload->data();
    $file1 = $upload_data['file_name'];
   }

这工作正常。非 jpeg 的文件 |GIF 未上传。但用户不会收到任何错误消息。我希望用户在上传其他图像类型时显示该特定错误。请帮忙

我试过这个,但失败了。

    try 1 : $this->template->load_partial('admin/admin_master', 'admin/form', $error); 
    try 2. : loading view with $error

谢谢

您不能将视图与错误消息相关联吗?例如:

$file1 = '';

你把:

$this->load->view('error_view', $error, $file1);

您必须制作一个名为"error_view.php"的单独视图页面。