CodeIgniter文件插入数据库,但不插入文件夹

时间:2018-10-16 11:46:56

标签: php codeigniter codeigniter-3

public function index(){
    $image = null;//tem var
    $config['upload_path'] = './assets/uploads/';
    $config['allowed_types'] = 'gif|jpg|jpeg|jpe|png';
    $config['max_size']      = '4000000';

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

    $this->form_validation->set_rules('title', 'Album Title', 'required');

    if($this->form_validation->run() == FALSE){
        $data['imagePath'] = base_url().'assets/uploads/';
        $data['album'] = $this->gallery->getAlbum();
        $this->load->view('admin/album', $data);
    }else{
        if (! $this->upload->do_upload('image')){//file upload
            $this->image = null;
        }else{
            $tem = array('upload_data' => $this->upload->data());
            $this->image = $tem["upload_data"]["file_name"];
        }//end else

         $data=array(
            'title' => $this->input->post('title'),
            'featured' => $this->image,
            'created_on' =>  date("Y-m-d")
         );

         if($this->gallery->createAlbum($data)){
            $this->session->set_flashdata('created','Album Has Been Created');
            redirect("admin");
         }
    }   
}

public function viewGallery($album_id){
    $config['upload_path']          = FCPATH.'assets/uploads/';
    $config['allowed_types']        = 'gif|jpg|jpeg|jpe|png';
    $config['max_size']             = 10000;
    $this->load->library('upload', $config);

    $data['imagePath'] = base_url().'assets/uploads/';
    $data['images'] = $this->gallery->getGalleryWithId($album_id);
    $data['album_id'] = $album_id;
    $this->load->view('addGallery', $data);
}

上载到数据库,但不上载指定的文件夹... 不知道下一步该怎么办.. 任何帮助都会真的很好。 我不知道将文件上传到的路径文件夹名放在哪里。唯一可以上传到数据库的东西。

预先感谢

2 个答案:

答案 0 :(得分:0)

尝试添加FCPATH

$config['upload_path'] = FCPATH.'/assets/uploads/';

答案 1 :(得分:0)

尝试这个。 首先,定义要在其中插入文件的任何文件夹名称。 就像在这种情况下,我在结尾处将文件夹名称命名为“ title”。

if($this->form_validation->run())     
        {  
            $title=$this->input->post('title');

            $config['upload_path']          = './assets/courses/'.$title;
            $config['allowed_types']        = 'gif|jpg|png|jpeg';
            $config['max_size']             = 1000;
            $config['max_width']            = 500;
            $config['max_height']           = 300;
            $this->load->library('upload', $config);
            if (!is_dir('./assets/courses/'.$title)) {
             mkdir('./assets/courses/'.$title, 0777, TRUE);
         }

希望如此对您有帮助。