PHP ftp_put() 期望参数 1 为资源,尝试将文件上传到远程 ftp 服务器时给出的布尔值

PHP ftp_put() expects parameter 1 to be resource, boolean given when trying to upload a file to a remote ftp server

我正在尝试将求职者提交的简历上传到远程 ftp 服务器。

我已将所有步骤包装到“if...else echo”语句中,它们都成功了(fopen、ftp_connect、ftp_login),但它卡在了 fpt_fput 错误的语句:

ftp_put() expects parameter 1 to be resource, boolean given in /var/www/*******/phpmailer/sendmail.php on line 286

我检查过它是否可能是 SELinux,但它不是 运行 在该服务器上。

这是 php 文件中该部分的代码:

$location = "uploads/" . $finalCV;
//move_uploaded_file($_FILES['applCV']['tmp_name'], $location);

//Move uploaded & renamed CV to server
if($fp = fopen($location, 'r'))
  echo "File Open Successful. ";
  else {
    echo "File Open Unsuccessful. ";
  }

if($conn_id = ftp_connect("some.server"))
  echo "FTP Connection Established Successfully. ";
else {
  echo "FTP Connection Failed. ";
  }

$ftpuser = "wynand";
$ftppasswd = "********";

if($login = ftp_login($conn_id, $ftpuser, $ftppasswd)) {
  echo "FTP Login Successful. ";
}
 else {
   echo "FTP Login Unsuccessful. ";
 }

if(ftp_put($login, $location, $fp, FTP_ASCII)) {
  echo "Successfully uploaded CV. ";
}
  else {
    echo "There was a problem uploading CV. ";
  }

你的 $login 有结果 ftp_login(),但是 ftp_put() 想要 resource $ftp

来自文档的示例 ftp_put

<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';

// 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);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
   echo "successfully uploaded $file\n";
} else {
   echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>

ftp_put() 的第一个参数取 ftp_connect() 结果。尝试

if(ftp_put($conn_id, $location, $fp, FTP_ASCII)) {
  echo "Successfully uploaded CV. ";
}

如果你想在本地文件上使用打开文件指针(在你的代码中使用它:))尝试ftp_fput()