Home > php教程 > php手册 > 修复ThinkPHP3.2.3官方FTP上传同名文件覆盖问题

修复ThinkPHP3.2.3官方FTP上传同名文件覆盖问题

WBOY
Release: 2016-06-07 11:34:12
Original
2283 people have browsed it

在官网提供的FTP上传类文件存在错误!
设定rootpath/**<br>      * 检测上传根目录<br>      * @param string $rootpath   根目录<br>      * @return boolean true-检测通过,false-检测失败<br>      */<br>     public function checkRootPath($rootpath){<br>         /* 设置根目录 */<br>         $this->rootPath = ftp_pwd($this->link);<br> <br>         if(!@ftp_chdir($this->link, $this->rootPath)){<br>             $this->error = '上传根目录不存在!';<br>             return false;<br>         }<br>         return true;<br>     }重写save方法 /**<br>      * 保存指定文件<br>      * @param  array   $file    保存的文件信息<br>      * @param  boolean $replace 同名文件是否覆盖<br>      * @return boolean          保存状态,true-成功,false-失败<br>      */<br>     public function save($file, $replace=true) {<br>         $filename = $this->rootPath . $file['savepath'] . $file['savename'];<br>         /* 不覆盖同名文件 */<br>         if (!$replace) {<br>             ftp_chdir($this->link, $this->rootPath . $file['savepath']);<br>             $ftpFileList = ftp_nlist($this->link, ".");<br>             if(in_array($file['savename'], $ftpFileList)) {<br>                 $this->error = '存在同名文件' . $file['savename'];<br>                 return false;<br>             }<br>         }<br>         /* 移动文件 */<br>         if (!ftp_put($this->link, $filename, $file['tmp_name'], FTP_BINARY)) {<br>             $this->error = '文件上传保存错误!';<br>             return false;<br>         }<br>         return true;<br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template