我有一个可用的文本表单,我有一个文件上传表单,可以使用codeigniter
文档中的确切示例,但我似乎无法将两者放在一起。
我想要一个允许文本和文件上传的表单。文本应该转到数据库,并且存储在DB中的filepath
存储文件。
答案 0 :(得分:0)
您需要的表格:
<?php echo form_open_multipart('upload/do_upload');?>
Text: <input type="text" name="usertext" size="20" />
<br /><br />
File: <input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
<?php echo form_close();?>
在上传控制器中:
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
// upload error area
}
else
{
$data = array('upload_data' => $this->upload->data());
//upload success area
$userfile = $upload_data['file_name']; // the uploaded file name
$usertext = $this->input->post('usertext'); // the text from form
// Here you can insert the value of $usertext to db
}
}