2011-04-09 19:30
浏览 86


Is it possible to upload a file to the FTP server using PHP script while the same script is downloading the meant file from somewhere else? So at the time script is downloading it should upload the file in real-time.

图片转代码服务由CSDN问答提供 功能建议

是否可以使用PHP脚本将文件上传到FTP服务器,同时相同的脚本从 别的地方? 因此,在下载脚本时,它应该实时上传文件。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanfang7757 2011-04-09 19:42

    Easy as cake, in theory. First, see FTP function here: Then we use FOPEN wrappers ( ) to open the file we want to read, and send it over.

    To modify the example:

    // open some file for reading
    $file = 'somefile.txt';
    $fp = fopen('' . $file, 'r');
    // 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);
    // try to upload $file
    if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
        echo "Successfully uploaded $file
    } else {
        echo "There was a problem while uploading $file
    // close the connection and the file handler

    Oh, and you might want non-blocking sometimes:

    解决 无用
    打赏 举报
  • 查看更多回答(2条)

相关推荐 更多相似问题