How to send all files from a folder via FTP in PHP?

1

I need to get all files from a local folder and send via FTP to a folder on the server.

Explanation:

I have a folder with images (.jpg) of products that at the time of registration generate an ID in the mysql database and put it as the name in the image.

I need to take these images and take them to another server via FTP, so it would not be functional to select or even manually do the process, so I need a way via PHP programming that I then schedule in the server cron for execute.

Thank you

    
asked by anonymous 05.01.2018 / 14:14

1 answer

0

Use link

An upload example:

<?php
$ftp_server = '<endereço do ftp>';
$ftp_user_name = '<usuario>';
$ftp_user_pass = '<senha>';

//Arquivo de origem
$file = '/pasta/no/servidor/de/origem/imagem.jpg';

//Aonde será salvo
$remote_file = 'pasta/no/servidor/remoto/imagem.jpg';

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
    echo "Upload de $file completo\n";
} else {
    echo "Erro ao enviar o $file\n";
}

ftp_close($conn_id);

If you want to send all of a folder you can use opendir or scanndir or FileSystem

    
05.01.2018 / 14:36