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