Welcome Guest, Not a member yet? Register   Sign In
Why does uploading images fail in this application?
#1

(This post was last modified: 09-03-2020, 04:38 AM by Ajax30.)

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

[font=Arial,]The code below correctly hashes the filename before inserting it in the [/font]avatar [font=Arial,]column, but the upload itself never happens.[/font]


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'),
        ];
}

[font=Arial,]I have a XAMPP server on Windows 10, so it is unlikely that there are permission issues on the images folder.[/font]
Reply
#2

Maybe because your missing the ending forward slash / on the upload_path?
What did you Try? What did you Get? What did you Expect?

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

I wish it was that. It is not.
Reply
#4

(This post was last modified: 09-03-2020, 12:03 PM by demyr.)

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); 
Reply
#5

(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?
Reply
#6

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

// Initialize the Configuration
$this->upload->initialize($config); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB