如何在php ftp上传中覆盖现有的文件夹或文件?

时间:2017-10-03 07:13:24

标签: php codeigniter ftp

如果使用 ftp_put 通过php ftp存在,如何覆盖文件夹/文件。 默认情况下不会覆盖文件。

<manifest ... >
<supports-screens android:smallScreens="false"
                  android:normalScreens="false"
                  android:largeScreens="true"
                  android:xlargeScreens="true"
                  android:requiresSmallestWidthDp="600" />
...
<application ... >
    ...
</application>

其他{

} }

2 个答案:

答案 0 :(得分:0)

这取决于FTP服务器的实现。如果不允许文件覆盖,请先上传前删除文件。

答案 1 :(得分:0)

   function ftp_putAll($conn_id, $src_dir, $dst_dir){
  $d = dir($src_dir);

    while($file = $d->read()) { // do this for each file in the directory

        if ($file != "." && $file != "..") { // to prevent an infinite loop

            if (is_dir($src_dir."/".$file)) { // do the following if it is a directory

                if (!@ftp_chdir($conn_id, $dst_dir."/".$file)) {

                    ftp_mkdir($conn_id, $dst_dir."/".$file); // create directories that do not yet exist                                                
                }


                ftp_putAll($conn_id, $src_dir."/".$file, $dst_dir."/".$file); // recursive part

            } else {


                @ftp_put( $conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY);
            }
        }
    }
    $d->close();
}

你可以试试上面的代码。

以下是功能参数

连接ID, 源路径, 目的地路径

相关问题