1

In codeigniter i have a form which contains some text and file(input type=file) fields. Some text fields are required. When i fill the form with file but missed one required field and submit the form. All fields are again repopulate the text other than file field . How can i get the selected files when form submission failed.

I tried set_value() but it seems not work.

and one more thing i can upload multiple files at a time:

$data = array ( 'name'=>'data_sheet[]',
                        'id'=>'data_sheet',
                        'class'=>'form-control',
                        'value'=>set_value('data_sheet', $data_sheet), 
                        'onchange'=>'validateFileInput(this)',
                      );
                    echo form_upload($data,'','multiple');

Here is the validation :

$this->form_validation->set_rules('name','name' ,'trim|required');
    $this->form_validation->set_rules('data_sheet','data sheet','trim');
if ($this->form_validation->run() == false)
    {
        $this->template->write_view('content', 'user/user_form',$data,TRUE);
    }

When i set the set_value like :

set_value=json_encode($_FILES)

<input type="file" name="data_sheet[]" value="{"data_sheet":{"name":["download.jpg"],"type":["image\/jpeg"],"tmp_name":["\/tmp\/phpTxQzNe"],"error":[0],"size":[4792]}}" id="data_sheet" class="form-control" onchange="validateFileInput(this)" multiple="">

How can i use thos to upload the file

Vini
  • 967
  • 1
  • 15
  • 33

1 Answers1

2

Modify your code to be like this:

      $data = array ( 'name'=>'data_sheet[]',
                    'id'=>'data_sheet',
                    'class'=>'form-control',
                    'value'=>$_FILES['data_sheet[]']['tmp_name'],
                    'onchange'=>'validateFileInput(this)',
                  );
                echo form_upload($data,'','multiple');
Nere
  • 4,097
  • 5
  • 31
  • 71