简体   繁体   中英

PHP Form post to TXT file on remote FTP

Here is the script that writes form data to txt file on same server (Linux). On every post it generates new file.

$myfile='/home/mysite/public_html/nar/fis_'.date('D_Mi').'_'.date('dmY_Hi').'.txt';

$fh=fopen($myfile,"w"); 
    # Now UTF-8 - Add byte order mark 
    fwrite($fh, pack("CCC",0xef,0xbb,0xbf)); 
    fwrite($fh,$upisufajl); 
    fclose($fh);

But now I need it to write on remote FTP server with username and password that is on Windows.

I have address: ftp://89.142.185.206/new_files/ and username and password.

What do I need to do? Examples would be appreciated.

Thanks guys

Since i assume that you have successfully written content to your text file, make use of this below script to login to FTP Server to upload your text file.

<?php
     $ftp_server="";
     $ftp_user_name="";
     $ftp_user_pass="";
     $file = "";//your textfile
     $remote_file = "remfile.txt";


     $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 "successfully uploaded $file\n";
        exit;
     } else {
        echo "There was a problem while uploading $file\n";
        exit;
        }
     ftp_close($conn_id);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM