查看代码
<form id="form1" method="post" enctype="multipart/form-data" action='<?php echo base_url();?>index.php/setup_con/upload'>
<input type="file" name="userfile" id="userfile" required="required"/>
</form>
<form id="form2" method="post" enctype="multipart/form-data" action='<?php echo base_url();?>index.php/setup_con/register'>
<input type="text" name="name" id="name"/>
<input type="text" name="city" id="city"/>
<input type="text" name="mobile" id="mobile"/>
<input type="submit" value="Submit" />
</form>
控制器代码
function upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '800';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
echo "File is Not valid/File does not select";
$error = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
$img_name = $data ['upload_data']['file_name'];
echo "'<img src='".base_url()."uploads/".$img_name."' class='preview'>";
}
}
function register()
{
$this->form_validation->set_rules('name','Name', 'trim|required');
$this->form_validation->set_rules('city','city', 'trim|required');
$this->form_validation->set_rules('mobile','mobile', 'trim|required');
if($this->form_validation->run() == FALSE)
{
}
else
{
$data = $this->register_model->register();
}
}
我已经在codeigniter中使用ajax从第一个表单上传图像,控制器正在上传,这里将只上传图像这个控制器,但我想图像名称发送寄存器控制器,我将在电阻表中插入图像名称、名称、城市和monbile。
请帮我,
我怎样才能成功地做到这一点