PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php 简单ftp文件上传范例

原创
2016-07-25 08:43:12 886浏览

php上传单个文件到ftp服务器的演示范例

  1. // FTP access parameters
  2. $host = 'ftp.example.org';
  3. $usr = 'example_user';
  4. $pwd = 'example_password';
  5. // file to move:
  6. $local_file = './example.txt';
  7. $ftp_path = '/data/example.txt';
  8. // connect to FTP server (port 21)
  9. $conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");
  10. // send access parameters
  11. ftp_login($conn_id, $usr, $pwd) or die("Cannot login");
  12. // turn on passive mode transfers (some servers need this)
  13. // ftp_pasv ($conn_id, true);
  14. // perform file upload
  15. $upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);
  16. // check upload status:
  17. print (!$upload) ? 'Cannot upload' : 'Upload complete';
  18. print "\n";
  19. /*
  20. ** Chmod the file (just as example)
  21. */
  22. // If you are using PHP4 then you need to use this code:
  23. // (because the "ftp_chmod" command is just available in PHP5+)
  24. if (!function_exists('ftp_chmod')) {
  25. function ftp_chmod($ftp_stream, $mode, $filename){
  26. return ftp_site($ftp_stream, sprintf('CHMOD %o %s', $mode, $filename));
  27. }
  28. }
  29. // try to chmod the new file to 666 (writeable)
  30. if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) {
  31. print $ftp_path . " chmoded successfully to 666\n";
  32. } else {
  33. print "could not chmod $file\n";
  34. }
  35. // close the FTP stream
  36. ftp_close($conn_id);
复制代码

文件上传, php, ftp


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。