dousuo8400 2015-06-16 13:32
浏览 23

PHP FTP上传功能

i have this function in PHP:

function UploadFileToFTP($local_path, $remote_path, $file, $filename) {
    global $settings;

    $remote_path = 'public_html/'.$remote_path;

    $ftp_server = $settings["IntegraFTP_H"];
    $ftp_user_name = $settings["IntegraFTP_U"];
    $ftp_user_pass = $settings["IntegraFTP_P"];

    //first save the file locally
    file_put_contents($local_path.$filename, $file);

    //login
    $conn_id = ftp_connect($ftp_server);
    ftp_pasv($conn_id, true); 
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

    // check connection
    if((!$conn_id) || (!$login_result)) { 
        echo "FTP connection has failed!";
    }

    //change directory
    ftp_chdir($conn_id, $remote_path);
    $upload = ftp_put($conn_id, $filename, $local_path.$filename, FTP_BINARY);

    // check upload status
    if(!$upload) { 
        echo "FTP upload has failed!";
    }
    // close the FTP stream 
    ftp_close($conn_id);
}

i call it here:

UploadFileToFTP('p/website/uploaded_media/', 'media/', $_FILES["file"]["tmp_name"], $filename);

the selected file is being moved into the local directory and also being uploaded to FTP however the file is becoming corrupt because it is not being uploaded correctly.

how can i get the file uploading properly?

  • 写回答

2条回答 默认 最新

  • douyi4544 2015-06-16 13:51
    关注

    Depending on what kind of file you're moving you may need to switch from FTP_BINARY to FTP_ASCII

    http://forums.devshed.com/ftp-help-113/ftp_ascii-ftp_binary-59975.html

    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思