link,true);" method to switch to passive mode; finally re-upload the file on the client. Can."/> link,true);" method to switch to passive mode; finally re-upload the file on the client. Can.">

Home  >  Article  >  Backend Development  >  What to do if php ftp_put fails

What to do if php ftp_put fails

藏色散人
藏色散人Original
2020-07-24 11:12:153494browse

php Solution to ftp_put failure: First open "Upload/Driver/Ftp.class.php"; then use the "ftp_pasv($this->link,true);" method to switch to passive mode; finally Just re-upload the file on the client.

What to do if php ftp_put fails

Recommended: "PHP Tutorial"

PHP Upload FTP driver ftp_put function upload failure problem

2 servers, one for ftp server and one for web server.

I use the Upload class of thinkphp3.2 and use the upload FTP driver, but it says file saving failure every time.

I am looking for the answer. I have tested both asynchronous and synchronous, but neither works. The remote /tmp/ and ftp directories also have 777 permissions.

Thinkphp should be very mature. Later I found some answers in the official documents, including the explanation mode

ftp server active mode, ftp server passive mode, I use ftp_pasv($this-> ;link,true); Switch to passive mode and the client can upload files smoothly.

Here is the solution

Upload/Driver/Ftp.class.php sava function

public function save($file, $replace=true) {
        $filename = $file['rootPath']. $file['savepath'] . $file['savename'];
        /* 不覆盖同名文件 */
        // if (!$replace && is_file($filename)) {
        //     $this->error = '存在同名文件' . $file['savename'];
        //     return false;
        // }
        ftp_pasv($this->link,true);
        ftp_pwd($this->link);
        $filename=$file['savename'];
        if (!ftp_put($this->link, $filename, $file['tmp_name'],FTP_ASCII)) {
            $this->error = '文件上传FTP错误!';
            return false;
        }
        return true;
    }

The above is the detailed content of What to do if php ftp_put fails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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