我想upload
codeigniter
中的一张照片。但是我得到了这个错误
不成功=您没有选择要上传的文件。
我的代码:
function uploadImageAvatar(){
$config = array(
'upload_path' => "/public_html/assets/Vitrin/Avatars/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => FALSE,
'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($_FILES['image_file']['tmp_name']))
{
echo "successful";
}
else
{
echo "unsuccessful=".$this->upload->display_errors();
}
}
我的HTML:
<form action="{{base_url().'cp/Users/uploadImageAvatar'}}" method="post" enctype="multipart/form-data" id="upload_form">
<input name="image_file" type="file" required="true" />
<input type="submit" value="upload" id="submit-btn" />
</form>
我哪里错了?
答案 0 :(得分:3)
更改此行
if($this->upload->do_upload($_FILES['image_file']['tmp_name']))
到
if($this->upload->do_upload('image_file'))