Welcome Guest, Not a member yet? Register   Sign In
File Not Move To Destination Folder
#1

I am having a problem uploading an image file to a destination folder in my CodeIgniter application and it is not working at all. I have referred so many articles and downloaded some working one but they wouldn't work once in my application and I am thinking it might be my .htaccess file or what. When I remove the upload $this->upload->do_upload('fileupload') path of the doUpload function and remove the if conditional statement, record got inserted in the database successfully even with extracting the name of the uploaded file and inserting it in the database table but once I put the $this->upload->do_upload('fileupload'), it will not work, meaning the Codeigniter do_upload() is not moving the file.

Please check my code doUpload() function :


,,,

Code:
public function doUpload()
        {              
                $config['upload_path'] = './Adverts/';  //Adverts is a folder created in the directory where i have codeigniter application folder
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '100048';
                $config['file_name'] = $_FILES['fileupload']['name'];

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

                if ($this->upload->do_upload('fileupload'))
                {
                    $data2 = array(
                              'AdvertCode'=>$this->input->post('advertcode'),
                              'CustomersName'=>$this->input->post('customersname'),
                              'AdvertSubject'=>$this->input->post('advertsubject'),
                              'AdvertMessage'=>$this->input->post('editor1'),
                              'AdvertPhotoName'=>$config['file_name'],
                              'Addedby'=>$this->input->post('addedby')
                            );

                        $this->db->insert('mytable', $data2);

            $this->session->set_flashdata('Added Successfully','Record  successfully added');
                            $this->loadRecord();                    
                }
                else
                {  
                        echo 'Error uploading file';                                                                                                                          
                }
        }

,,,

Below is my .htaccess file

,,,

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]


,,,

Please help me on this as it is killing me big time. Attached to this post is my folder structure.

I appreciate all efforts in advance.

Regards,

Attached Files Thumbnail(s)
   
Reply
#2

You should not use the config filename the upload library will assign the filename
from the upload.

Remark out that config value and see if it works.
What did you Try? What did you Get? What did you Expect?

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

(12-17-2019, 09:02 AM)InsiteFX Wrote: You should not use the config filename the upload library will assign the filename
from the upload.

Remark out that config value and see if it works.

I have just done that now and it was not working as well. The error message is "The upload path does not appear to be valid." . I have changed the upload path from './Adverts/' to './Adverts' to 'Adverts/' to 'Adverts' and i even changed it to the full path of the domain e.g https://example.com/MySite/Adverts but still showing the error "The upload path does not appear to be valid." . You can see the folder structure of my project in the attachment in my post and i hope it is not my .htaccess file not permitting that? I have the .htaccess file code in the post as well. Please assist me if you can. I wonder why people don't provide help on this platform, they only read and leave.
Reply
#4

Add RewriteBase "/" after Rewrite On.

You can try replacing the / with the full path to your site.
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