Send file to another server using Codeigniter [closed]

0

I have a Web System that I will move to a hosting. More I have the system with 2 banks (one for the site and the other is in my house for path of files, documents, logs, etc), the script will stay in the hosting and the path of the files on the server in my house. The problem and the following, for security and space consumption issues I can not send these files to the hosting. Then the user will send the document by the form, PHP connects to the bank in my house and saves the data of the document and sends the file to my house.

How can I do this?

I've been thinking of sending via Ajax request to my local server and passing the return for error validation. What do you think?

    
asked by anonymous 09.08.2017 / 22:07

1 answer

1

I solved the problem with class FTP of codeigniter which is the framework I'm using. I set the second connection of the database to my home and soon after doing the insertion, editing or delete the data, php saves the file in the hosting in a temporary folder and I execute the following script:

      $caminho_temp= "Arquivos/TEMP/DE/{$this->input->post('numero')}_{$this->input->post('ano')}{$arquivo['file_ext']}";

      $source = $caminho_temp;
        $this->load->library('ftp');
        //FTP configuration
        $ftp_config['hostname'] = '###.150.##.123';
        $ftp_config['username'] = '@@@@@@';
        $ftp_config['password'] = '@@@@@@';
        $ftp_config['debug']    = FALSE;

        //Connect to the remote server
        if($this->ftp->connect($ftp_config) == TRUE){

          //File upload path of remote server
          $destino = "/Arquivos/DE/{$fileName}{$arquivo['file_ext']}";
          $destino_url = "Arquivos/DE/{$fileName}{$arquivo['file_ext']}";

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

          //Close FTP connection
          $this->ftp->close();
          @unlink($source);
        }else{
          $this->session->set_flashdata('error','Problema de conexão com o servidor de documentos.');
          @unlink($source);
          redirect(base_url()."admin/atos/de/editar/".$this->input->post('id'));
        }

After uploading via FTP I delete the file from the temporary folder in the hosting or if the upload failed, I also delete it.

Process can get a bit slow for files larger than 5mb.

    
11.08.2017 / 15:46