0

Am having difficulties uploading images with codeigniter it keeps saying that i didn't select a file to upload.

this is my code

function do_upload()
{
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'jpg|png';
    $config['max_size'] = '3000';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

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

    if (!$this->upload->do_upload()){
        echo $this->upload->display_errors();
    }else{
        echo $this->upload->data();
    }
}

it doesn't even send the image to the directory.

3
  • maybe some output would be helpful? Commented Jan 18, 2012 at 15:14
  • i dont get, pls explain. am not pro! Commented Jan 18, 2012 at 15:27
  • @DanielBarde: Please include any specific error message or output you are receiving. Additionally, you may want to include your view code as well. Commented Jan 18, 2012 at 16:00

3 Answers 3

1

try this function instead :

function upload_done() {
 $config['overwrite'] = TRUE;
 $config['encrypt_name'] = FALSE;
 $config['remove_spaces'] = TRUE;
 $config['upload_path'] = '/var/www/uploadfiles/'; // use an absolute path
 $config['allowed_types'] = 'jpg|png';
 $config['max_size'] = '0'; 
 if ( ! is_dir($config['upload_path']) ) die("THE UPLOAD DIRECTORY DOES NOT EXIST");
 $this->load->library('upload',$config);
 if ( ! $this->upload->do_upload() )
 {
  echo "UPLOAD ERROR ! ".$this->upload->display_errors();
 } else {
  echo "THE IMAGE HAS BEEN UPLOADED : "; var_dump( $this->upload->data() );
 }
}
Sign up to request clarification or add additional context in comments.

2 Comments

but i want to run a query at once and store the full path to the image on my images table how do i get the full path. this is the array that contains all the image info. $this->upload->data()
You'll find what you need in $t=$this->upload->data(); $full_path_to_image=$t['full_path']; to store all the array, just do : $this->db->insert('images_table', $t);
0

Make sure your html looks like below.

    <input type="file" name="userfile" size="20" />

Codeigniter's upload library assumes the name to be "userfile"

Comments

0

You need to change the call to do_upload() depending on the name you have given the form input. Lets say you have this code in your HTML:

<input type="file" name="image" />

You need to change:

$this->upload->do_upload()

to

$this->upload->do_upload('image')

By default CodeIgniter assumes the name is "userfile".

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.