嗨,我已经能够使用 codeigniter 将图像路径上传到数据库,但我似乎无法将类别选项传递给数据库。我有带有 2 个选项的下拉菜单,然后我想将它传递给控制器,以便我可以将其插入数据库。
这是我的代码:
我的观点
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<br />
<select name="album" id="album"> // my dropdown list
<option value="staff">Album Staff</option>
<option value="gallery">Gallery</option>
</select>
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
这是我的控制器
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = './assets/images';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['overwrite'] = TRUE;
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = FALSE;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
$upload_info=$this->upload->data();
$insert_data = array(
'imgfilename' => $upload_info['file_name'],
'imgfilepath' => $upload_info['file_path'],
'album' => $this->input->post('album') //trying to get the value from select in view
);
$this->db->insert('db_images', $insert_data);
}
}
}
?>
应该怎么做?任何解决方案?