“没有选择要上传的文件”当使用codeigniter上传时 [英] "did not select a file to upload" when uploading using codeigniter
本文介绍了“没有选择要上传的文件”当使用codeigniter上传时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试上传图片,但它总是给我您没有选择要上传的文件。
im trying to upload an image but it always give me "You did not select a file to upload."
我的控制器
function add()
{
$thedate=date('Y/n/j h:i:s');
$replace = array(":"," ","/");
$newname=str_ireplace($replace, "-", $thedate);
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['file_name']=$newname;
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
//$this->upload->initialize($config);
$this->load->library('form_validation');
$this->form_validation->set_rules('title','title','trim|required');
$this->form_validation->set_rules('description','Description','trim|required');
$image1=$this->input->post('image');
if ($this->form_validation->run()==FALSE){
$this->addview();
return false;
}
if (!$this->upload->do_upload($image1)) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_error', $error);
}
else {
$mage=$this->upload->do_upload($image1);
$data =array(
'title'=>$this->input->post('title'),
'descrip'=>$this->input->post('description'),
'image' => $mage['file_name']
);
$this->load->model('member_functions');
$q=$this->member_functions->insert($data);
}}
所有文件要求和文件权限已设置,那个错误。有人可以告诉我我做错了什么
all the file requirements and the file permissions are set but i still get the that eror. can someone please tell me what am i doing wrong
推荐答案
参数 $ this-& > do_upload()
函数应该是表单字段的名称。 (如果调用它而不使用参数 userfile
)。在你的情况下,它似乎应该是'形象'。而不是:
Parameter to $this->upload->do_upload()
function should be the name of the form field. (If you call it without parameters userfile
would be used). It seems in your case it should be 'image'. Instead of:
$image1=$this->input->post('image');
它应该是:
$image1='image';
这篇关于“没有选择要上传的文件”当使用codeigniter上传时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文