我在远程主机上有一个网站。 我试图让php页面通过ftp将文件上传到另一台远程服务器。
我尝试上传的服务器有这些目录(都有权限777):
/
/public_html
/public_html/files
比如说这些是ftp的细节:
host: example.com
user: user
pass: pass
port: 21
任何人都可以帮助我理解为什么这段代码不起作用:
$file = 'C:\Users\[my username]\Desktop\somefile.txt';
$remote_file = '/public_html/files/file.txt';
// set up basic connection
$conn_id = ftp_connect("example.com",21);
// login with username and password
$login_result = ftp_login($conn_id, "user", "pass");
echo $login_result;
// 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);
当我运行它时,我收到以下消息:
Warning: ftp_put(C:\Users\User\Desktop\somefile.txt) [function.ftp-put]: failed to open stream: No such file or directory in /home/user/public_html/page.php on line 11
任何帮助都非常感谢我已经疯狂地研究并且已经尝试了很长时间。
答案 0 :(得分:0)
$ remote_file =' files / file.txt&#39 ;; 你应该试试这个