Rumah  >  Artikel  >  pembangunan bahagian belakang  >  又一个php FTP上传类

又一个php FTP上传类

WBOY
WBOYasal
2016-07-25 09:04:33949semak imbas
  1. /**
  2. php ftp上传类
  3. link:bbs.it-home.org
  4. date:2013/2/25
  5. */
  6. //R FTP 处理;
  7. class ftp {
  8. var $ftpUrl = '58.123.24.32';
  9. var $ftpUser = 'test123';
  10. var $ftpPass = 'yourpassword';
  11. var $ftpDir = '/others/';
  12. var $ftpR = ''; //R ftp资源;
  13. var $status = '';
  14. //R 1:成功;2:无法连接ftp;3:用户错误;
  15. function ftp() {
  16. if ($this->ftpR = ftp_connect($this->ftpUrl, 21)) {
  17. if (ftp_login($this->ftpR, $this->ftpUser, $this->ftpPass)) {
  18. if (!empty($this->ftpDir)) {
  19. ftp_chdir($this->ftpR, $this->ftpDir);
  20. }
  21. ftp_pasv($this->ftpR, true);//R 启用被动模式;
  22. $this->status = 1;
  23. } else {
  24. $this->status = 3;
  25. }
  26. } else {
  27. $this->status = 2;
  28. }
  29. }
  30. //R 切换目录;
  31. function cd($dir) {
  32. return ftp_chdir($this->ftpR, $dir);
  33. }
  34. //R 返回当前路劲;
  35. function pwd() {
  36. return ftp_pwd($this->ftpR);
  37. }
  38. //R 上传文件;
  39. function put($localFile, $remoteFile = '') {
  40. if ($remoteFile == '') {
  41. $remoteFile = end(explode('/', $localFile));
  42. }
  43. $res = ftp_nb_put($this->ftpR, $remoteFile, $localFile, FTP_BINARY);
  44. while ($res == FTP_MOREDATA) {
  45. $res = ftp_nb_continue($this->ftpR);
  46. }
  47. if ($res == FTP_FINISHED) {
  48. return true;
  49. } elseif ($res == FTP_FAILED) {
  50. return false;
  51. }
  52. }
  53. //R 下载文件;
  54. function get($remoteFile, $localFile = '') {
  55. if ($localFile == '') {
  56. $localFile = end(explode('/', $remoteFile));
  57. }
  58. if (ftp_get($this->ftpR, $localFile, $remoteFile, FTP_BINARY)) {
  59. $flag = true;
  60. } else {
  61. $flag = false;
  62. }
  63. return $flag;
  64. }
  65. //R 文件大小;
  66. function size($file) {
  67. return ftp_size($this->ftpR, $file);
  68. }
  69. //R 文件是否存在;
  70. function isFile($file) {
  71. if ($this->size($file) >= 0) {
  72. return true;
  73. } else {
  74. return false;
  75. }
  76. }
  77. //R 文件时间
  78. function fileTime($file) {
  79. return ftp_mdtm($this->ftpR, $file);
  80. }
  81. //R 删除文件;
  82. function unlink($file) {
  83. return ftp_delete($this->ftpR, $file);
  84. }
  85. function nlist($dir = '/service/resource/') {
  86. return ftp_nlist($this->ftpR, $dir);
  87. }
  88. //R 关闭连接;
  89. function bye() {
  90. return ftp_close($this->ftpR);
  91. }
  92. }
  93. ?>
复制代码


Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn