1

アップロードファイルのタイトルと概要のフィールドをいくつか使用して、ファイルアップロードを作成したいと思います。私もこの質問を見ましたが、完全には理解できません。

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

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

1 に答える 1

3

ファイルのアップロード以外のすべてのフィールドの検証を確認する必要があります。そこで検証が成功したら、ファイルを確認します。例:

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.
   }
}
于 2012-04-29T13:39:27.993 に答える