php ftp上传文件报错:ftp_put(): php_connect_nonb() failed: Operation now in progress (115)
请问大神这是什么原因?
关于php ftp的问题
答案:2 悬赏:80 手机版
解决时间 2021-03-05 21:07
- 提问者网友:無理詩人
- 2021-03-05 08:22
最佳答案
- 五星知识达人网友:蓝房子
- 2021-03-05 08:56
你去后盾人那里查一下视频吧,然后你就会明白了,他们那里的讲师非常专业,一听就懂。
全部回答
- 1楼网友:胯下狙击手
- 2021-03-05 10:28
class ftp {
private $rootpath;
private $error = ''; //上传错误信息
private $link;
private $config = array(
'host' => '', //服务器
'port' => 21, //端口
'timeout' => 90, //超时时间
'username' => '', //用户名
'password' => '', //密码
);
public function __construct($config){
$this->config = array_merge($this->config, $config);
if(!$this->login()){
e($this->error);
}
}
public function checkrootpath($rootpath){
$this->rootpath = ftp_pwd($this->link) . '/' . ltrim($rootpath, '/');
if(!@ftp_chdir($this->link, $this->rootpath)){
$this->error = '上传根目录不存在!';
return false;
}
return true;
}
public function checksavepath($savepath){
if (!$this->mkdir($savepath)) {
return false;
} else {
//todo:检测目录是否可写
return true;
}
}
public function save($file, $replace=true) {
$filename = $this->rootpath . $file['savepath'] . $file['savename'];
// if (!$replace && is_file($filename)) {
// $this->error = '存在同名文件' . $file['savename'];
// return false;
// }
if (!ftp_put($this->link, $filename, $file['tmp_name'], ftp_binary)) {
$this->error = '文件上传保存错误!';
return false;
}
return true;
}
public function mkdir($savepath){
$dir = $this->rootpath . $savepath;
if(ftp_chdir($this->link, $dir)){
return true;
}
if(ftp_mkdir($this->link, $dir)){
return true;
} elseif($this->mkdir(dirname($savepath)) && ftp_mkdir($this->link, $dir)) {
return true;
} else {
$this->error = "目录 {$savepath} 创建失败!";
return false;
}
}
public function geterror(){
return $this->error;
}
private function login(){
extract($this->config);
$this->link = ftp_connect($host, $port, $timeout);
if($this->link) {
if (ftp_login($this->link, $username, $password)) {
return true;
} else {
$this->error = "无法登录到ftp服务器:username - {$username}";
}
} else {
$this->error = "无法连接到ftp服务器:{$host}";
}
return false;
}
public function __destruct() {
ftp_close($this->link);
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯