上传客户特定项目的图片?

时间:2019-04-08 10:49:43

标签: php codeigniter

我是Codeignter和php的新手。我正在开发项目管理应用程序,在该应用程序中我必须为某些项目上传图像。我在Codeignter中无法上传特定项目ID的图像。

项目ID已在图片表数据库中设置为外键。

这是我的上传控制器

public function file_data(){
        //validate the form data 

        $this->form_validation->set_rules('pic_title', 'Picture Title', 'required');

        if ($this->form_validation->run() == FALSE){
            $this->load->view('upload_form');
        }else{

            //get the form values
            $data['pic_title'] = $this->input->post('pic_title');
            $data['pic_desc'] = $this->input->post('pic_desc');


            //file upload code 
            //set file upload settings 
            $config['upload_path']          = APPPATH. '../assets/uploads/';
            $config['allowed_types']        = 'gif|jpg|png';
            $config['max_size']             = 10240;

            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload('pic_file')){
                $error = array('error' => $this->upload->display_errors());
                $this->load->view('upload_form', $error);
            }else{

                //file is uploaded successfully
                //now get the file uploaded data 
                $upload_data = $this->upload->data();

                //get the uploaded file name
                $data['pic_file'] = $upload_data['file_name'];

                //store pic data to the db
                $this->pic_model->store_pic_data($data);

                redirect('/');
            }
            $this->load->view('footer');
        }

这是我的pic_model

function get_all_pics(){
        $all_pics = $this->db->get('pictures');
        return $all_pics->result();
    }

    //save picture data to db
    function store_pic_data($data){
        $insert_data['pic_title'] = $data['pic_title'];

        $insert_data['pic_file'] = $data['pic_file'];
                $insert_data['projectID']= $data['projectID'];
        $query = $this->db->insert('pictures', $insert_data);
    }
    // to get pictures for a particular project    
      public function view_picture($id){

    $this->db->select("*"); 
  $this->db->from('pictures');
$this->db->where('projectID' ,$id);
  //$this->db->join('client', 'client.Client_id = projects.Client_id');
  $query = $this->db->get();
  return $query->result();
 }

这是我的上传表单视图


function get_all_pics(){
        $all_pics = $this->db->get('pictures');
        return $all_pics->result();
    }

    //save picture data to db
    function store_pic_data($data){
        $insert_data['pic_title'] = $data['pic_title'];

        $insert_data['pic_file'] = $data['pic_file'];
                $insert_data['projectID']= $data['projectID'];
        $query = $this->db->insert('pictures', $insert_data);
    }
    // to get pictures for a particular project    
      public function view_picture($id){

    $this->db->select("*"); 
  $this->db->from('pictures');
$this->db->where('projectID' ,$id);
  //$this->db->join('client', 'client.Client_id = projects.Client_id');
  $query = $this->db->get();
  return $query->result();
 }

这是我的项目仪表板,我想将该项目作为参考插入图片表中。

This is my project dasboard, i want to insert that project as a reference into picture table

1 个答案:

答案 0 :(得分:0)

我通过将项目ID设置为会话ID并访问并将其插入图片表来解决此问题。