php ftp上传不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5425766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ftp upload not working
提问by seoppc
File is not uploading to FTP and errors: Warning: ftp_put() [function.ftp-put]: Can't open that file: No such file or directory coming. We are using following code:
文件未上传到 FTP 和错误:警告:ftp_put() [function.ftp-put]:无法打开该文件:没有这样的文件或目录。我们正在使用以下代码:
$server = 'ftp.domain.com';
$ftp_user_name = '[email protected]';
$ftp_user_pass = 'password';
$dest = 'files/test.txt';
$source = 'test.txt';
$src = ini_get("upload_tmp_dir");
$connection = ftp_connect($server);
$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);
if (!$connection || !$login) { die('Connection attempt failed!'); }
$upload = ftp_put($connection, $dest, $source, FTP_BINARY);
if (!$upload) { echo 'FTP upload failed!'; }
ftp_close($connection);
回答by Ryre
Here's an answer from the comments of php.net on ftp_put:
以下是 php.net 对 ftp_put 评论的回答:
Found the prob, you can't put a path to the destination file (even though I can do that in the dos ftp client...?)
找到了问题,你不能把路径放到目标文件中(即使我可以在 dos ftp 客户端中做到这一点......?)
e.g. - this doesn't work
例如 - 这不起作用
ftp_put($conn, '/www/site/file.html','c:/wamp/www/site/file.html',FTP_BINARY);
you have to put
你必须把
ftp_chdir($conn, '/www/site/');
ftp_put($conn,'file.html', 'c:/wamp/www/site/file.html', FTP_BINARY );
回答by user3002411
I had same problem and I solved it using ftp_nb_put(). Same function but it allows your program to run more connections or something:-)
我遇到了同样的问题,我使用ftp_nb_put()解决了它。相同的功能,但它允许您的程序运行更多连接或其他东西:-)