在我的Laravel应用程序中,我尝试允许用户将基本文件上传到远程FTP,并且我已经能够通过PHP创建与FTP的连接但是我的代码到达ftp_put的那一刻()它抛出了这个错误。
ftp_put(): Command STOR failed
我已经验证我可以通过FileZilla将文件上传到我的FTP,但它确实允许我这样做。任何形式的洞察都会很棒。
以下是我目前正在使用的代码。
if (Input::hasFile('file')) {
$path = Input::file('file')->getRealPath();
$uploadpath = '/users/';
$usr = 'login';
$pwd = 'password';
// file to move:
$local_file = $path;
$ftp_path = $uploadpath;
// connect to FTP server
$conn_id = ftp_connect('ftp.url.com');
// send access parameters
ftp_login($conn_id, $usr, $pwd);
// turn on passive mode transfers (some servers need this)
ftp_pasv ($conn_id, true);
// perform file upload
ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
ftp_close($conn_id);
}
答案 0 :(得分:2)
找到了解决方案!
我的上传路径只是路径本身,在我附加到上传路径以包含文件名后,它还允许上传。
因此,如果有人在同样的情况下遇到同样的问题:
$uploadpath = '/users/' . $file_name;
$ftp_path = $uploadpath;