CodeIgniter Forums
Why does uploading images fail in this application? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Why does uploading images fail in this application? (/showthread.php?tid=77457)



Why does uploading images fail in this application? - Ajax30 - 09-03-2020

I am working on a Social Network application with Codeigniter 3, Ioan-Auth and Bootstrap 4. More details HERE.

The code below correctly hashes the filename before inserting it in the avatar column, but the upload itself never happens.


Code:
if ($this->form_validation->run() === TRUE)
    {
        //more code here

        $config['upload_path'] = './assets/img/avatars';
        $config['file_ext_tolower']     = TRUE;
        $config['allowed_types']        = 'gif|jpg|jpeg|png';
        $config['max_size']             = 1024;
        $config['max_width']            = 1024;
        $config['max_height']           = 1024;
        $config['encrypt_name']         = TRUE;
        $this->load->library('upload', $config);

        if (!$this->upload->do_upload('userfile')){
            $error = array('error' => $this->upload->display_errors());
            $file_name = null;
        } else {
            $file_name = $this->upload->data('file_name');
        }

        $additional_data = [
            'first_name' => $this->input->post('first_name'),
            'last_name' => $this->input->post('last_name'),
            'avatar' =>  $file_name,
            'company' => $this->input->post('company'),
            'phone' => $this->input->post('phone'),
        ];
}

I have a XAMPP server on Windows 10, so it is unlikely that there are permission issues on the images folder.


RE: Why does uploading images fail in this application? - InsiteFX - 09-03-2020

Maybe because your missing the ending forward slash / on the upload_path?


RE: Why does uploading images fail in this application? - Ajax30 - 09-03-2020

I wish it was that. It is not.


RE: Why does uploading images fail in this application? - demyr - 09-03-2020

Have you tried checking each suitable points ? For example, after your upload path line you can :

PHP Code:
$config['upload_path'] = './assets/img/avatars';

echo 
$config['upload_path];
die();
// or print_r() where suitable.. 

So that you can see the results of each code block.

By the way, $this->load->library part did not work for me as well and I used it as below in one of my projects:

PHP Code:
//$this->load->library('upload', $config); instead of this, use below
  $this->upload->initialize($config); 



RE: Why does uploading images fail in this application? - Ajax30 - 09-03-2020

(09-03-2020, 12:03 PM)demyr Wrote: Have you tried checking each suitable points ? For example, after your upload path line you can :

PHP Code:
$config['upload_path'] = './assets/img/avatars';

echo 
$config['upload_path];
die();
// or print_r() where suitable.. 

So that you can see the results of each code block.

By the way, $this->load->library part did not work for me as well and I used it as below in one of my projects:

PHP Code:
//$this->load->library('upload', $config); instead of this, use below
  $this->upload->initialize($config); 

Nice, but how do I load the upload library then?


RE: Why does uploading images fail in this application? - InsiteFX - 09-04-2020

PHP Code:
// You could also autoload it
$this->load->library('upload');

// Initialize the Configuration
$this->upload->initialize($config);