我想通过视图->控制器->模型传递文本输入和2个文件,当我运行此代码时,总是出现“您没有选择要上传的文件”的错误。
查看- 在此视图中,我输入文本和两个名为“myFile”和“myDoc”的加载文件输入
<form action="<?=site_url('blog_maintain/save')?>" method = "post" enctype="multipart/form-data"><li class="field" style="display:inline"><p><i class = "icon-docs"></i> หัวข้อ :
<input class="text input" type="text" placeholder="Topic Input" name = "topic" id ="topic" required="required">
</p></li>
<li class="field" style="display:inline"><p><i class = "icon-menu"></i> คำอธิบาย :
<input class="text input" type="text" placeholder="Short Description" name = "desc" id = "desc" required="required">
</p></li>
<li class="field" style="display:inline"><p><i class = "icon-picture"></i> รูปภาพ :
******<input type="file" name = "myFile" id = "myFile" required="required" accept="image/*">******
</p></li>
<li class="field" style="display:inline"><p><i class = "icon-attach"></i> ไฟล์แนบ :
***<input type="file" name = "myDoc" id = "myDoc" accept=".doc,.docx,.pdf,.txt,.xls,.xlsx,.ppt,.pptx">***
</p></li>
<li class="field" style="display:inline"><p><i class = "icon-doc-text"></i>บทความ :
<textarea class="input textarea" placeholder="Description" rows="5" name = "text" id = "text" required="required"></textarea>
</p></li>
<input class="medium btn pill-left default push_seven two columns" type="submit" value = "upload" onclick = "return check();">
<input class="medium btn pill-right default two columns" type="Reset" value = "Reset">
模型- 在这个模型中,我将 $_POST 传递给控制器 save_blog()
public function save(){
$this->load->model('blog_maintain_helper');
$data['result'] = $this->blog_maintain_helper->save_blog();
$this->loadView('blogMaintainView',$data);
}
控制器
function save_blog(){
$config = array(
'upload_path' => 'server_path',
'allowed_types' => "gif|jpg|png|jpeg|pdf|doc|xml",
'overwrite' => TRUE,
);
get_instance()->load->library('upload', $this->config);
if($this->upload->do_upload())
{
echo "file upload success";
}
else
{
echo $this->upload->display_errors();
}
}