當我在同一視圖/站點上有兩個上載窗體時,Codeigniter中出現問題。看來Codeigniter只承認從一個表單提交。即使我在表單中更改輸入名稱,問題仍然存在。 下面是我的觀點和CONTROLER:在CodeIgniter中的相同視圖上的兩個窗體
查看:
<?php echo form_open_multipart('admin/upload/do_upload_ac');?>
<input type="file" name="actives" />
<br /><br />
<input class="btn btn-primary" type="submit" value="Add Active Emails" />
</form>
<?php echo form_open_multipart('admin/upload/do_upload_un');?>
<input type="file" name="unactives" />
<br /><br />
<input class="btn btn-primary" type="submit" value="Add Active Emails" />
</form>
發生了。控制器:
public function do_upload_ac()
{
header('Cache-Control: must-revalidate');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'csv';
$config['max_size'] = 0;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if (! $this->upload->do_upload('actives'))
{
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error', 'Csv Data Import failed!! Please check the file size or file type!');
//$this->load->view('admin/muc', $error);
redirect(base_url() . 'index.php/admin/muc');
}
else
{
$data = array('upload_data' => $this->upload->data());
$filename_ac = $this->upload->data('full_path');
$this->Upload_model->insert_csv_ac($filename_ac);
$this->Upload_model->clean_temp_ac();
$this->Upload_model->truncate_temp_ac();
$this->session->set_flashdata('success', 'Csv Data Imported Succesfully!');
//$this->load->view('success', $data);
//unlink($filename_ac);
redirect(base_url() . 'index.php/admin/muc');
}
}
public function do_upload_un()
{
header('Cache-Control: must-revalidate');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'csv';
$config['max_size'] = 0;
$this->load->library('upload', $config);
if (! $this->upload->do_upload('unactives'))
{
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error', 'Csv Data Import failed!! Please check the file size or file type!');
//$this->load->view('admin/muc', $error);
redirect(base_url() . 'index.php/admin/muc');
}
else
{
$data = array('upload_data' => $this->upload->data());
$filename_ac = $this->upload->data('full_path');
$this->Upload_model->insert_csv_un($filename_un);
$this->Upload_model->clean_temp_un();
$this->Upload_model->truncate_temp_un();
$this->session->set_flashdata('success', 'Csv Data Imported Succesfully!');
//$this->load->view('success', $data);
unlink($filename_un);
redirect(base_url() . 'index.php/admin/muc');
}
}
我正在尋找這裏類似的問題,但我發現一次上傳多個文件。有任何想法嗎?謝謝大家。
給你的表單一個ID,如id =「form1」和id =「form2」,然後使用jquery函數提交表單 –
謝謝,但它不工作。任何沒有jQuery的解決方案? – wishmaster75
可以用'''<?php echo form_close()>結束表單嗎? ?'''而不是''''''。並使用'''輸入類型=「提交」>'''而不是按鈕。 – kishor10d