Welcome Guest, Not a member yet? Register   Sign In
Image is not being uploaded into Database
#1

Hello

PHP Code:
           $slug str_replace(' ''-'$this->input->post('title'));
 
           $slug strtolower($slug);
            
 
           $subject_name str_replace(' ''-'$this->input->post('subject_name'));
 
           $subject_name strtolower($subject_name);

            
// Upload Image
            
$config['upload_path'] = 'assets/img/posts/';
            
$config['allowed_types'] = 'gif|jpg|png';
            
$config['encrypt_name'] = TRUE;
            
$config['max_size'] = '2048';
            
$config['max_width'] = '2000';
            
$config['max_height'] = '2000';
            
$this->load->library('upload'$config);
            
$this->upload->initialize($config);
                    
            
            
$file_name 'post_image';
            
            if(!
$this->upload->do_upload($file_name)){
                
varDebug($this->upload->display_errors());
                
$file_name base_url().'assets/img/noimage.jpg';
            } else {
                
$data = array('upload_data' => $this->upload->data($file_name));
            }

            
// Page Data
 
           $data = array(
                
'subject_id'    => $this->input->post('subject_id'),
                
'subject_name'    => $subject_name,
                
'user_id'        => $this->input->post('user_id'),
                
'username'        => $this->input->post('username'),
                
'slug'            => $slug,
                
'title'            => $this->input->post('title'),
                
'post_image'    => $file_name,
                
'body'            => $this->input->post('body'),
                
'is_published'    => $this->input->post('is_published'),
                
'is_featured'    => $this->input->post('is_featured'),
                
'in_menu'        => $this->input->post('in_menu'),
                
'is_commented'    => $this->input->post('is_commented'),
                
'order'            => $this->input->post('order'),
 
           );
            
 
           // Insert Page
 
           $this->Post_model->add($data); 

I already tried by commenting the $data = array('upload_data' => $this->upload->data($file_name)); just after the else to then use this on my array in the post_image value, and If I do that it throws me an error of post_image cannot be NULL...

PHP Code:
'post_image'    => $this->upload->data($file_name

Any help?

The Code works in general, I mean, it sends the file to the folder, the problem is that is does not upload the picture into the database under the post_image value. What it actually sends is the data inside the file_name variable that is just after initializing the upload config.


PHP Code:
$file_name = 'post_image'
I do Front-End development most of the time 
Reply
#2

PHP Code:
'post_image'    => $this->upload->data($file_name);

// Should be
'post_image'    => $this->upload->data('file_name'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(02-14-2018, 04:40 AM)InsiteFX Wrote:
PHP Code:
'post_image'    => $this->upload->data($file_name);

// Should be
'post_image'    => $this->upload->data('file_name'); 

You were right, its working now.
I do Front-End development most of the time 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB