在我的 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);
}
最佳答案
找到解决方案!
我的上传路径只是路径本身,在我向上传路径添加附加内容以包含文件名后,它也允许上传通过。
因此,如果有人在相同的情况下遇到相同的问题:
$uploadpath = '/users/' . $file_name;
$ftp_path = $uploadpath;
关于php - ftp_put() : Command STOR failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31440190/