【问题标题】:Uploading multiple files to FTP using UploadiFive使用 UploadiFive 将多个文件上传到 FTP
【发布时间】:2012-07-23 16:35:34
【问题描述】:

我一直在尝试使用 UploadiFive 将文件从单独的 Web 服务器上传到 FTP 服务器。 This StackOverflow 上的问题解决了这个问题,但没有解决问题。我正在使用以下代码(取自前面提到的问题)尝试从 UploadiFive 上传文件:

if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];                          // 1

//$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';  // 2
//$targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; // 3


$ftp_server = "***";  //address of ftp server.
$ftp_user_name = "***"; // Username
$ftp_user_pass = "***";   // Password
$conn_id = ftp_connect($ftp_server);
ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
ftp_pasv ( $conn_id, true );

if( ftp_fput($conn_id, 'TEST/' . $_FILES['Filedata']['name'], $tempFile, FTP_BINARY)){                       // 4
    echo true;
}else{
    echo false;
}

ftp_close($conn_id);

} else {
    echo false;
}

无论何时执行此代码,文件都不会出现在本地 Web 服务器或 FTP 服务器上。这段代码在uploadifive.php

【问题讨论】:

    标签: php javascript jquery file-upload ftp


    【解决方案1】:

    用此代码修复:

    if (!empty($_FILES)) {
    
        $ftp_server = "****";
        $ftp_user = "****";
        $ftp_password = "****";
    $tempFile   = $_FILES['Filedata']['tmp_name'];
    
        $file_to_upload = $tempFile;
        $remote_location = "/directoryname/". $_FILES['Filedata']['name'];
    
        // set up connection or exit with message
        $flink = ftp_connect($ftp_server) or exit("Can't connect to ftp server: $ftp_server");
    
        // login or at least try  
        if(ftp_login($flink, $ftp_user, $ftp_password)) {
    
    
         // if login successful use ftp_put to upload the file
         // if you upload binary files use mode FTP_BINARY
         if(ftp_put($flink, $remote_location, $file_to_upload, FTP_ASCII)) {
    
             echo "Success! File is uploaded!";
             } else {
                   echo "Can't upload file";
             }
        } else {
             echo "Can't login with this user & password";
        }
         // close the connection
         ftp_close($flink);
         }
    

    【讨论】:

      猜你喜欢
      • 2019-12-03
      • 2017-07-13
      • 1970-01-01
      • 2011-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多