FTP文件上传到PHP

问题描述 投票:1回答:0

我有一台Windows服务器,希望将其中的一些图像传输到我的FTP服务器。 下面是我的代码

    $file = "docs/1.png";
    $ftp_server = "";
    $ftp_user_name = "";
    $ftp_user_pass = '';
    $destination_file = "1.png";

    // set up basic connection
    $conn_id = ftp_connect($ftp_server);


    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

    // check connection
    if ((!$conn_id) || (!$login_result)) { 
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
        exit; 
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name";
    }
    echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
    // upload the file
    // ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 180);
    ftp_chdir($conn_id, "example/");
    echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
    // ftp_put($conn_id, $destination_file, $file, FTP_BINARY); 
    ftp_pasv($conn_id, true); 
    $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY); 

    // check upload statu
    if (!$upload) { 
    echo "FTP upload has failed!";
    } else {
    echo "Uploaded $source_file to $ftp_server as $destination_file";
    }

    // close the FTP stream 
    ftp_close($conn_id);

我正进入(状态 **

ftp_put():打开BINARY模式数据连接

**此错误和文件未上传。

php ftp upload
© www.soinside.com 2019 - 2024. All rights reserved.