0

我一直在尝试使用 UploadiFive 将文件从单独的 Web 服务器上传到 FTP 服务器。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

4

1 回答 1

0

使用此代码修复:

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);
     }
于 2012-07-23T16:51:41.637 回答