2
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);
}

Uploads to the database but not the folder specified... Don't know what to do next.. Any help will really be good. I don't know where to put the path foldername wherein the file should be uploaded. The only thing that is uploading to the database works.

Thanks in advance

Mhrishad
  • 246
  • 1
  • 18
Osei-Owusu
  • 201
  • 3
  • 6

2 Answers2

1

Try to add FCPATH

$config['upload_path'] = FCPATH.'/assets/uploads/';
Rudra
  • 156
  • 1
  • 4
  • 13
0

Try this one. First Define any folder name in which you want to insert the file. Like in this case i have made 'title' the folder name at my end.

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);
         }

Hope So this will help You.

Ammar Mehr
  • 67
  • 9