我试图将本地文件上传到在线服务器。我创建了一个FTP连接来上传文件,但无法正常工作。
这是我尝试的代码:
// connect and login to FTP server
$ftp_server = 'ftp.example.so';
$ftp_user_name = '[email protected]';
$ftp_user_pass = 'password';
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_user_name, $ftp_user_pass);
if($login) {
echo 'connected<br>';
$local_file = 'file_name.txt';
$server_dir = 'https://example.so/folder/';
// upload a file
if (ftp_put($ftp_conn, $server_dir, $local_file, FTP_ASCII)) {
echo "successfully uploaded $local_file\n";
exit;
} else {
echo "There was a problem while uploading $local_file\n";
exit;
}
}
运行此命令后,我得到了Warning: ftp_put(): Can't open that file: No such file or directory in D:\XAMPP\htdocs\project\upload.php on line 101
请检查'file_name.txt'的正确路径;
$remote_file
的ftp_put
自变量是FTP服务器上文件的路径。
您正在将URL传递给文件夹。
如果应该像:
$remote_file = "/folder/file_name.txt";