【发布时间】:2017-04-10 07:24:43
【问题描述】:
当我在同一个视图/站点上有两个上传表单时,我在 Codeigniter 中遇到问题。似乎 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 的任何解决方案?
-
请以
<?php echo form_close(); ?>结束表格,而不是</form>。并使用<input type="submit">代替按钮。 -
我做到了。但我的问题仍然在这里.....实际上是否可以在同一个视图上拥有两个上传表单,以及在控制器中上传两个类似的功能?
标签: php codeigniter