我的图像上传选项在我的codeigniter应用程序中不起作用。我怎样才能解决这个问题?

时间:2018-01-17 02:47:20

标签: php codeigniter

我的网站上有这样的问题。我创建了一个上传图片的选项。我已经搜索了很多次,但我没有找到解决方案。

这是我视图文件中的代码。

               <div class="form-group">
                            <label for="exampleFormControlFile1"><p>4 : Media * :</p></label>
                           <p> <input type="file"  name="file_name">
               </div>

这是我控制器中的代码。

public function create(){
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'jpg|png|jpeg';
        $this->load->library('upload', $config);
        $this->upload->do_upload('file_name');


        $file_name=$this->upload->data();
        $data=array(
            'institute'=>$this->input->post('institute'),
            'category'=>$this->input->post('category'),
            'content'=>$this->input->post('content'),
            'relavent_authority'=>$this->input->post('relavent_authority'),
            'multimedia'=>$file_name['file_name'],
            'created'=>date("Y-m-d H:i:s"),
        );

            $data['id']=$this->Question_model->add_data($data);
            $data['authority'] = $this->Question_model->getAuthority();
            if($this->input->post('share')=="yes"){
                $this->load->view('header',$data);
                $this->load->view('questions/share',$data['id']);
                $this->load->view('footer');
            }
     }   

对于上传的文件,我创建了一个名为uploads的文件夹。但上传不起作用。它也没有给出错误。这段代码有什么问题?

1 个答案:

答案 0 :(得分:1)

通过添加&#34; enctype&#34;

在您的表单标记上尝试此操作
from django.contrib.auth.models import User
from django.db import models
相关问题