首页 > 后端开发 > php教程 > php使用ftp函数实现简单上传功能

php使用ftp函数实现简单上传功能

WBOY
发布: 2016-07-25 09:04:37
原创
888 人浏览过
  1. /**

  2. ftp上传文件
  3. link:bbs.it-home.org
  4. date:2013/2/25
  5. */
  6. $ftp_server = "192.168.8.8";
  7. $ftp_user = "test123";
  8. $ftp_pass = "yourpassword";
  9. // set up a connection or die

  10. $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
  11. $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);

  12. if ((!$conn_id) || (!$login_result)) {

  13. echo "FTP connection has failed!";
  14. echo "Attempted to connect to $ftp_server for user $ftp_user_name";
  15. exit;
  16. } else {
  17. echo "Connected to $ftp_server, for user $ftp_user_name";
  18. }
  19. // try to login

  20. $filename=date('Ymd').".xml";
  21. $source_file="/var/mydata/".$filename; //源地址
  22. echo $source_file;
  23. $destination_file="/admin/ftplog/".$filename; //目标地址
  24. $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY) or die("Couldn't connect to $ftp_server");
  25. ftp_quit($conn_id);
  26. if (!$upload) {

  27. echo "FTP upload has failed!";
  28. } else {
  29. echo "Uploaded $source_file to $ftp_server as $destination_file";
  30. }
  31. ftp_close($conn_id);
  32. ?>
复制代码


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板