我一直在尝试使用UploadiFive从单独的Web服务器上传文件到FTP服务器。 StackOverflow上的This问题解决了这个问题,但没有解决问题。我使用以下代码(取自前面提到的问题)尝试从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
答案 0 :(得分: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);
}