简体   繁体   English

CodeIgniter - 结合表单验证和文件上传

[英]CodeIgniter - Combine form validation and file upload

I would like to create file upload with some fields for title and summary of upload file. 我想用上传文件的标题和摘要的一些字段创建文件上传。 I have also looked at this question, but I don't understand it completly. 我也看过这个问题,但我完全不了解它。

function someform()
{
   // some variables for fields
   ($this->form_validation->run() == FALSE)
   {

   }
   else
   {
      // how to check if the file was uploaded?
   }
}

You should check validation for all the other fields other than the file upload. 您应该检查除文件上载之外的所有其他字段的验证。 After the validation succeeds there, check the files. 验证成功后,检查文件。 Example: 例:

function someform()
{
   // some variables for fields
   ($this->form_validation->run() == TRUE)
   {

       $config['upload_path'] = './uploads/';
       $config['allowed_types'] = 'gif|jpg|png';
       $config['max_size'] = '100';
       $config['max_width'] = '1024';
       $config['max_height'] = '768';

       $this->load->library('upload', $config);


       $fileTagName = 'myfile'; // e.g <input type='file' name='myfile' />    
       if ($this->upload->do_upload($fileTagName))) {
           //Success in validation of all fields.
       }
       else {
           //Failed to upload file.
           echo $this->upload->display_errors('', '');
       }
   }
   else
   {
      //Other fields failed.
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM