Yii2 FTP文件上传无法正常工作

时间:2017-10-16 13:48:47

标签: php ftp yii2 ftp-client

我使用yii2mod / yii2-ftp模块上传FTP上传。但它没有直接上传临时文件。

//This method will provide data to any test method that declares that its Data Provider
//is named "test1"
@DataProvider(name = "test1")
public Object[][] createData1() {
 return new Object[][] {
   { "Cedric", new Integer(36) },
   { "Anne", new Integer(37)},
 };
}

//This test method declares that its data should be supplied by the Data Provider
//named "test1"
@Test(dataProvider = "test1")
public void verifyData1(String n1, Integer n2) {
 System.out.println(n1 + " " + n2);
} 

输出返回错误

  

“dir(/ tmp / phpizYNd7):无法打开目录:不是目录”

1 个答案:

答案 0 :(得分:0)

在yii2mod / yii2-ftp中putAll方法考虑作为目录。因此无法上传文件。检查参数是函数内的文件或文件夹。

供应商/ yii2mod / yii2-ftp / ftpClient.php第606行

public function putAll($source_directory, $target_directory, $mode = FTP_BINARY)
{

    if(is_dir($source_directory)){

        $d = dir($source_directory);
        // do this for each file in the directory

        while ($file = $d->read()) {

            // to prevent an infinite loop
            if ($file != '.' && $file != '..') {
                // do the following if it is a directory
                if (is_dir($source_directory . '/' . $file)) {
                    if (!@$this->ftp->chdir($target_directory . '/' . $file)) {
                        // create directories that do not yet exist
                        $this->ftp->mkdir($target_directory . '/' . $file);
                    }
                    // recursive part
                    $this->putAll(
                        $source_directory . '/' . $file, $target_directory . '/' . $file,
                        $mode
                    );
                } else {
                    // put the files
                    $this->ftp->put(
                        $target_directory . '/' . $file, $source_directory . '/' . $file,
                        $mode
                    );
                }
            }
        }
    }else{
        $this->ftp->put(
            $target_directory, $source_directory,
            $mode
        );
    }

    return $this;
}