There is a form where the user can add an image, it is necessary that it be saved to an FTP server. All sites have the same example, on the basis of which such code was created ...

$filep = $_FILES['foto']['tmp_name']; $ftp_server = 'xx.xxx.xx.xxx'; $ftp_user_name = 'admin'; $ftp_user_pass = 'xxxxxxxxxxx'; $paths = "/АРХИВ/".$filep; $name = $_FILES['foto']['name']; $conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); if ((!$conn_id) || (!$login_result)) { echo "Соединение не установлено!"; echo "Попытка подключения $ftp_server для пользователя: $ftp_user_name"; exit; } else { echo "Соединение установлено $ftp_server для пользователя: $ftp_user_name"; } $upload = ftp_put($conn_id, $paths. '/'.$name, $filep, FTP_BINARY); if (!$upload) { echo "Загрузка не выполнена!"; } else { echo "Выполнена загрузка $name на $ftp_server"; } ftp_close($conn_id); set_time_limit(300); 

As a result, there is nothing on the server) is there a problem in the code? Or is it necessary to change something in the settings of the FTP server itself? Unfortunately online examples on this topic are hard to find ...

  • What messages are displayed? What errors occur? - Anton Shchyrov
  • "Connection established, loading failed" - hidden
  • Check or allow the server to save the file, that is, in the properties of the directory where you save the file is allowed to write. - Dmitriy Kondratiuk
  • @hidden Try adding ftp_pasv($conn_id, true) before downloading. And also try replacing ftp_put with ftp_raw and see what the server really returns - Anton Shchyrov
  • @DmitriyKondratiuk recording is allowed in the directory, under this account also write permissions are set ... files are added normally via Filezilla ... - hidden

1 answer 1

Judging by

 $upload = ftp_put($conn_id, $paths. '/'.$name, $filep, FTP_BINARY); 

Where

 $paths = "/АРХИВ/".$filep; 

You have everything written in the archive АРХИВ from the root.

try at least like this:
$upload = ftp_put($conn_id, $_SERVER['DOCUMENT_ROOT'] . $paths. '/'.$name, $filep, FTP_BINARY);

  • Yes, she’s messing with directories and file names, changed $paths = "/АРХИВ/".$filep; on $paths = "/АРХИВ/".$name; . Changed the line $upload = ftp_put($conn_id, $paths, $filep, FTP_BINARY); and everything began to work. Thank! - hidden
  • @hidden, not at all, please contact :) - Nikolay