dpl74687 2019-04-06 15:38
浏览 53

php RecursiveIterators - 备份public_html文件夹但忽略一个文件夹[重复]

I need to allow my user to backup his public_html folder, but I want to zip everything except my own "rules folder". I've found a very nice answer here (working pretty good, but the exported zip file contains my rules folder aswell). So the question is how to detect the folder and just ignore it?

$files = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($rootPath),
    RecursiveIteratorIterator::LEAVES_ONLY
);
$exclude = array("rulles_folder");
foreach ($files as $name => $file) {
    var_dump($file -> getFilename());
    if ($file -> isDir() && !in_array($file -> getFilename(), $exclude)) {
        salta();
    } else {
        // Skip directories (they would be added automatically)
        if (!$file -> isDir()) {
            // Get real and relative path for current file
            $filePath = $file -> getRealPath();
            $relativePath = substr($filePath, strlen($rootPath) + 0);
            // Add current file to archive
            $zip -> addFile($filePath, $relativePath);
        }
    }
}
function salta () {
    ;
}

var_dump returns

string(1) "." string(2) ".." string(9) ".DS_Store" string(9) "index.php"

and so on, no Folder names at all, so when I call

if ($file -> isDir() && !in_array($file -> getFilename(), $a_excluir))

nothing happens because no folder names exists

Any suggestion please?

Thanks

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题