0

I am working on codeigniter project. All is working on my localhost. Now i have shifted all the things on server. I am also using cloudfare.

the problem is when i try to upload image it shows me blank screen. Following is my controller code.

// Add Data
    function add(){
        $data['pageTitle']=$this->lang->line('siteTitle');
        // Breadcrumbs
        $this->breadcrumbs->push('Dashboard','admin/dashboard');
        $this->breadcrumbs->push('Category List','admin/category/index');
        $this->breadcrumbs->push('Add Category','admin/category/add');
        // Load View
        // Form Submit
        $this->form_validation->set_rules('_cat_title','Title','required|is_unique[pu_project_category.c_title]');
        $this->form_validation->set_rules('_cat_slug','Slug','required');
        $this->form_validation->set_rules('_cat_desc','Description','required');
        if($this->form_validation->run()==TRUE){
            if($this->upload->do_upload('_cat_image')){
                $image=$this->upload->data();
                $image=$image['file_name'];
            }else{
                $image='No Image';
            }
            $data['resUpload']=$this->upload->display_errors();
            $data['res']=$this->Category_Model->add($image);
        }
        // Load View
        $this->load->view('admin/common/header',$data);
        $this->load->view('admin/common/left-sidebar',$data);
        $this->load->view('admin/category/add',$data);
        $this->load->view('admin/common/footer',$data);
    }

Following is configuration code for uploading file,

// Upload Configuration
$config['upload_path']          = './project_images/';
$config['allowed_types']        = 'gif|jpg|png|jpeg|zip';
$config['max_size']             = '2000';
$this->load->library('upload', $config);
$this->upload->initialize($config);

Please help me to solve this problem and tell me where i doing wrong.

2

1 Answer 1

0

try this

    public function add()
{



      $this->form_validation->set_rules('_cat_slug','Slug','required');

   if($this->form_validation->run() == TRUE)
            {
                   $this->load->model('welcome_model');//change this with your model



               //image upload
                $config['upload_path'] = './uploads/';
                $config['allowed_types'] = 'png|gif|jpg|jpeg';
                $config['max_size']    = '7000';
                $this->load->library('upload',$config);
                if ( ! $this->upload->do_upload('image'))
                {
                   $error = array('error' => $this->upload->display_errors());
                    $this->load->view('upload_view', $error);  //loads the view display.php with error
                }

                $upload_data=$this->upload->data();

                $image=$upload_data['file_name'];

                $this->load->view('upload_view');

                     $data= array(
                    '_cat_slug' => $this->input->post('_cat_slug'),
                    'image' => $image

                ); //loads view display.php with data
               $this->welcome_model->registre($data);//change this with your model function name
            }


            else
            {  

            echo validation_errors();


            }

}

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer but i have tried this number of times. It did not solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.