0

My image is not get inserted while uploading using codeigniter:

function add_newblog()
{
       $sess_id = $this->session->userdata('id');
       $result['query'] = $this->login_model->profile($sess_id);
        foreach($result['query'] as $row)
          {
           $email = $row->blogger_email; 
           $url = $row->blogger_url; 
           $author = $row->blogger_name; 
       if ($this->input->post('submit')) {

        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '0';
        $config['max_width'] = '0';
        $config['max_height'] = '0';

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

        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            $media = 'No Image Uploaded';

        $title = $this->input->post("title");
        $category = $this->input->post('category');
        $content = $this->input->post('content'); 
                $this->blog_model->add_newblog($sess_id,$title,$category,$content,$media,$email,$url,$author);

                $this->session->set_flashdata('valid', 'Blog Created without Image');
                redirect('content_writer/add_blog');
            }
        else {
            $data = array('upload_data' => $this->upload->data());
            $data = $this->upload->data();

            $media = $data['file_name'];
            $title = $this->input->post("title");
            $category = $this->input->post('category');
            $content = $this->input->post('content'); 

                $this->blog_model->add_newblog($sess_id,$title,$category,$content,$media,$email,$url,$author);
                $this->session->set_flashdata('valid', 'Blog Created');
                redirect('content_writer/add_blog');
            }

        }
        else{
             $this->session->set_flashdata('invalid', 'Invalid');
                redirect('content_writer/add_blog');
        }
      }
    }

The else condition always works. The image name does not get saved in the image path.

4
  • 1
    not inserted means not inserted into database or not upload in folder? Commented Apr 27, 2015 at 5:59
  • @saty both ...whenever i try to insert an image or media through this upload field (view page query- <div class="control-group"> <label class="control-label" for="fileInput">Upload Media</label> <div class="controls"> <input class="input-file uniform_on" name="userfile" id="fileInput" type="file"> </div> </div>) it always work not uploaded file condition... Commented Apr 27, 2015 at 6:10
  • always it shows the value in $media = no image uploaded Commented Apr 27, 2015 at 6:14
  • increse $config['max_size'] = '100'; $config['max_width'] = '200'; $config['max_height'] = '200' and try; Commented Apr 27, 2015 at 6:16

3 Answers 3

1

the problem is here in this line

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

instead use

$config['upload_path'] = 'uploads/<folder name>'; 

OR incase you want to save the image directly in uploads folder just use

$config['upload_path'] = 'uploads/';

as well as make your that you form in the veiw section is open with form_open_multipart() hope this will solve your problem

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

Comments

0

Set your max_size, max_width and max_height. This would be an example below.

$config['max_size'] = '3000';
$config['max_width']  = '1500';
$config['max_height']  = '1500';

5 Comments

I see @salty said it first, sorry
if you give any suggestion the put a comment not given answer
I cant, don't have the reputation yet :/ @saty
@saty, @ David Gilliam,@ karvin.developer ....hey i need to keep the image width and height constant ..if uploaded image is less than the given width and height it does not wanted to insert do any one have suggestions.....
@Nayanz, sorry I am now seeing this a year later, but did you ever figure this out?
0

You havent passed the image name in $this->upload->do_upload() method.

use your

input type='file' name=myDoc

$this->upload->do_upload("myDoc")

Comments

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.