Home » Php » php – Upload image url via ftp in Codeigniter

php – Upload image url via ftp in Codeigniter

Posted by: admin February 25, 2020 Leave a comment

Questions:

I wanted to upload image by entering url and store it into the database via ftp but it shows a error says that

Unable to locate the source file. Please check your path.

 if($this->input->post('submit')){
            //Upload to the local server
            $config['upload_path'] = './images/';
            $config['allowed_types'] = '*';
            $this->load->library('upload', $config);


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

                //Get uploaded file information
                $upload_data = $this->upload->data();
                $fileName = $upload_data['file_name'];

                //File path at local server
                $source = "uploads/".$fileName;

                //Load codeigniter FTP class
                $this->load->library('ftp');

                //FTP configuration
                $ftp_config['hostname'] = 'xxxxx'; 
                $ftp_config['username'] = 'xxxxx';
                $ftp_config['password'] = 'xxxxx';
                $ftp_config['debug']    = TRUE;

                //Connect to the remote server
                $this->ftp->connect($ftp_config);

                //File upload path of remote server
                $destination = '/assets/'.$fileName;
                echo $destination;

                //Upload file to the remote server
                $this->ftp->upload($source, ".".$destination);

                //Close FTP connection
                $this->ftp->close();

                //Delete file from local server
                @unlink($source);

            }
        }

How can I solve this?

How to&Answers: