这是控制器:
public function category()
{
if($this->form_validation->run()==FALSE)
{
$this->load->view('admin/home');
}
else{
$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);
$image_data=$_POST['file'];
if ( ! $this->upload->do_upload())
{
// no file uploaded or failed upload
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/home', $error);
}
else
{
// success
$data = array('upload_data' => $this->upload->data());
$this->your_upload_model->add($title, $description, $data["file_name"]);
$this->load->view('upload_success', $data);
}
}
}
这是视图:
<?php echo validation_errors();?>
<?php echo form_open_multipart('login/category');?>
<?php
if(isset($error))
{
echo $error;
}
?>
<table>
<tr>
<td align=right>Logo:</td>
<td><input type="file" name="file"></td>
<td><input type="submit" value="submit"></td>
</tr>
</table>
我收到两个错误:
- 消息:未定义的索引:文件
- 您没有选择要上传的文件。
即使文本字段名称相同并且我使用了form_open_multipart()
. 此外,图像未上传,错误无济于事。