PHP的 - ftp_put未能打开流? [英] PHP - ftp_put failed to open stream?
本文介绍了PHP的 - ftp_put未能打开流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在远程主机上有一个网站。
我试图让php页面通过ftp将文件上传到另一个远程服务器。
我试图上传的服务器有这些目录(所有人都有权限777):
/
/ public_html
/ public_html / files
可以说例如这些是ftp详细信息:
host:example.com
user:user
pass:pass
port:21
任何人都可以请帮我理解为什么这段代码不工作:
$ file ='C:\Users\ [我的用户名] \Desktop\somefile.txt';
$ remote_file ='/public_html/files/file.txt';
//设置基本连接
$ conn_id = ftp_connect(example.com,21);
//使用用户名和密码登录
$ login_result = ftp_login($ conn_id,user,pass);
echo $ login_result;
//上传文件
if(ftp_put($ conn_id,$ remote_file,$ file,FTP_ASCII)){
echo成功上传$ file \\\
;
} else {
echo上传$ file \\\
时出现问题;
}
//关闭连接
ftp_close($ conn_id);
运行它时,我收到以下消息:
警告:ftp_put(C:\Users\User\Desktop\somefile.txt)[function.ftp-put]:无法打开流:没有这样的文件或第11行/home/user/public_html/page.php中的目录
我研究得像疯了一样,并且一直在努力尝试很久。
$ remote_file ='files / file.txt';您应该试试这个
I have a website on a remote host. I am trying to get the php page to upload a file to another remote server through ftp.
The server I am trying to upload to has these directories(all have permission 777):
/
/public_html
/public_html/files
lets say for example these were the ftp details:
host: example.com
user: user
pass: pass
port: 21
can anyone please help me understand why this code isn't working:
$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);
when I run it I get the following message:
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
Any help is really appreciated ive researched like crazy and have been trying for ages.
解决方案
$remote_file = 'files/file.txt'; You should try this
这篇关于PHP的 - ftp_put未能打开流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文