【问题标题】:Image Type Validation in codeignitercodeigniter 中的图像类型验证
【发布时间】:2012-06-18 14:22:48
【问题描述】:

我是 Codeigniter 的新手。处理表单中包含图像的表单验证。在 CodeIgniter 中使用 Module MVC 扩展。

//上传图片我发现这个文件上传sn-p

   $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

谢谢

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

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

    之后

    $file1 = '';
    

    你说:

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

    您必须创建一个名为“error_view.php”的单独视图页面。

    【讨论】:

    • 但这将是一个不同的视图页面。我希望这成为我其他表单验证的一部分。
    • 不一定在同一页上,但那是另一回事。您正在寻找的是所谓的“表单验证回调”:[链接]codeigniter.com/user_guide/libraries/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    相关资源
    最近更新 更多