Welcome Guest, Not a member yet? Register   Sign In
Only upload if user set a value
#1

[eluser]Corbee[/eluser]
Hi,

I'm doing a file upload, and I needed it to only upload if the user has set a value to the image.

I tried using

Code:
if ($this->input->post('logo'))
            {
                $config['upload_path'] = './images/CarLogo';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size']    = '100';
                $config['max_width']  = '180';
                $config['max_height']  = '180';
                $config['overwrite'] = 'TRUE';
                $this->load->library('upload', $config);
            
                if(!$this->upload->do_upload('logo'))
                {
                    $this->upload->display_errors();
                    exit();
                }
                    $logo = $this->upload->data();
                    
                if ($logo['file_name'])
                {
                    $logo = $logo['file_name'];
                    $this->MManage->updatelogo($logo);
                }
            }

but if you do an echo on the $this->input->post('logo');
you'll realize that it is always blank whether user sets it or not.

What's wrong with my code?

Thanks
#2

[eluser]techgnome[/eluser]
Does using isset work?

Code:
if (isset($this->input->post('logo')))

-tg
#3

[eluser]LuckyFella73[/eluser]
You want to check if a FILE was selected so you have to check
the file array - for example:
Code:
<?php
if (isset($_FILES['logo']['name']) AND strlen($_FILES['logo']['name'])>0){
// upload here
}
?>
#4

[eluser]Corbee[/eluser]
Thanks, $_FILES works.




Theme © iAndrew 2016 - Forum software by © MyBB