php – 使用codeigniter上传时“没有选择要上传的文件”

前端之家收集整理的这篇文章主要介绍了php – 使用codeigniter上传时“没有选择要上传的文件”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图上传图像,但它总是给我“你没有选择要上传文件.”

我的控制器

  1. function add()
  2. {
  3.  
  4. $thedate=date('Y/n/j h:i:s');
  5. $replace = array(":"," ","/");
  6. $newname=str_ireplace($replace,"-",$thedate);
  7.  
  8. $config['upload_path'] = './upload/';
  9. $config['allowed_types'] = 'gif|jpg|png|jpeg';
  10. $config['file_name']=$newname;
  11. $config['max_size'] = '100';
  12. $config['max_width'] = '1024';
  13. $config['max_height'] = '768';
  14.  
  15. $this->load->library('upload',$config);
  16. //$this->upload->initialize($config);
  17. $this->load->library('form_validation');
  18.  
  19. $this->form_validation->set_rules('title','title','trim|required');
  20. $this->form_validation->set_rules('description','Description','trim|required');
  21. $image1=$this->input->post('image');
  22.  
  23.  
  24. if ($this->form_validation->run()==FALSE){
  25.  
  26. $this->addview();
  27.  
  28. return false;
  29.  
  30. }
  31.  
  32.  
  33. if (!$this->upload->do_upload($image1)) {
  34.  
  35. $error = array('error' => $this->upload->display_errors());
  36. $this->load->view('upload_error',$error);
  37.  
  38.  
  39. }
  40.  
  41. else {
  42. $mage=$this->upload->do_upload($image1);
  43.  
  44. $data =array(
  45. 'title'=>$this->input->post('title'),'descrip'=>$this->input->post('description'),'image' => $mage['file_name']
  46.  
  47. );
  48.  
  49.  
  50. $this->load->model('member_functions');
  51.  
  52. $q=$this->member_functions->insert($data);
  53. }}

设置了所有文件要求和文件权限,但我仍然得到了那个错误.有人可以告诉我,我做错了什么

参数$this-> upload-> do_upload()函数应该是表单字段的名称. (如果你在没有参数的情况下调用它,则会使用userfile).在你的情况下,它似乎应该是’形象’.代替:
  1. $image1=$this->input->post('image');

它应该是:

  1. $image1='image';

猜你在找的PHP相关文章