又一個php FTP上傳類

來源:互聯網
上載者:User
  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. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.