上传文件所有数据都正常运行,但文件上传未保存在服务器中,文件名也未获取
查看
<form class="form-horizontal" role="form" method="post" action="<?php echo base_url('main/sent'); ?>" id="frm1">
<input type="file" name="userfile">
</form>
控制器主 内部
public function sent(){
$config = array(
'upload_path' => "./inquery/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
var_dump($data);
}
答案 0 :(得分:2)
确保您的表单能够提交文件:
<form enctype="multipart/form-data" ...>
如上所述给出enctype属性,你必须完成!
让函数知道文件来自哪个字段:
if($this->upload->do_upload('userfile'))
...
答案 1 :(得分:0)
上传文件时,您需要将表单元素的enctype
属性设置为enctype="multipart/form-data"
如果上传不成功,我附加了一个else子句来显示错误。所以你可以找出原因!!!
public function sent(){
$config = array(
'upload_path' => "./inquery/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
var_dump($data);
}else{
print_r($this->upload->display_errors()));
}