如何在 PHP 中比较两个文件结构?

发布于 2024-08-31 04:06:47 字数 1678 浏览 2 评论 0原文

我有一个函数可以为我提供高达 n 级的完整文件结构,

function getDirectory($path = '.', $ignore = '') {
    $dirTree = array ();
    $dirTreeTemp = array ();
    $ignore[] = '.';
    $ignore[] = '..';

    $dh = @opendir($path);

    while (false !== ($file = readdir($dh))) {

        if (!in_array($file, $ignore)) {
            if (!is_dir("$path/$file")) {
//display of file and directory name with their modification time

                            $stat = stat("$path/$file");
                $statdir = stat("$path");


                   $dirTree["$path"][] = $file. " === ". 
                     date('Y-m-d H:i:s', $stat['mtime']) . " Directory == 
                   ".$path."===". date('Y-m-d H:i:s', $statdir['mtime']) ;

            } else {

                $dirTreeTemp = getDirectory("$path/$file", $ignore);
                if (is_array($dirTreeTemp))$dirTree = 
                               array_merge($dirTree, $dirTreeTemp);
            }
        }
    }
    closedir($dh);

    return $dirTree;
}

$ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquota');
//function call
$dirTree = getDirectory('.', $ignore);
//file structure array print
print_r($dirTree);

现在我的要求是,我有两个站点

  • 开发/测试站点 - 我在哪里 测试所有更改
  • 生产站点 - 我最终在那里 根据测试发布所有更改 开发站点

现在,例如,我已经在开发/测试站点中测试了图像上传,并且我发现在生产站点上发布是合适的,然后我将把开发/测试数据库详细信息完全传输到生产数据库,但现在我想比较文件结构以及将相应的图像文件传输到 Production 文件夹。

可能会出现这样的情况:当我通过编辑图像并以相同名称上传图像来更新图像时,现在在这种情况下图像文件已经存在,这将限制“file_exist”逻辑的使用,因此对于这些类型情况....如何比较两个文件结构以根据要求完成同步?

已编辑

要求必须是一个脚本,我将需要它作为 joomla 组件功能。.请按此回复。

I have a function which gives me the complete file structure upto n-level,

function getDirectory($path = '.', $ignore = '') {
    $dirTree = array ();
    $dirTreeTemp = array ();
    $ignore[] = '.';
    $ignore[] = '..';

    $dh = @opendir($path);

    while (false !== ($file = readdir($dh))) {

        if (!in_array($file, $ignore)) {
            if (!is_dir("$path/$file")) {
//display of file and directory name with their modification time

                            $stat = stat("$path/$file");
                $statdir = stat("$path");


                   $dirTree["$path"][] = $file. " === ". 
                     date('Y-m-d H:i:s', $stat['mtime']) . " Directory == 
                   ".$path."===". date('Y-m-d H:i:s', $statdir['mtime']) ;

            } else {

                $dirTreeTemp = getDirectory("$path/$file", $ignore);
                if (is_array($dirTreeTemp))$dirTree = 
                               array_merge($dirTree, $dirTreeTemp);
            }
        }
    }
    closedir($dh);

    return $dirTree;
}

$ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquota');
//function call
$dirTree = getDirectory('.', $ignore);
//file structure array print
print_r($dirTree);

Now here my requirement is , I have two sites

  • The Development/Test Site- where i do
    testing of all the changes
  • The Production Site- where I finally
    post all the changes as per test in
    development site

Now, for example, I have tested an image upload in the Development/test site, and i found it appropriate to publish on Production site then i will completely transfer the Development/Test DB detail to Production DB, but now I want to compare the files structure as well to transfer the corresponding image file to Production folder.

There could be the situation when I update the image by editing the image and upload it with same name, now in this case the image file would be already present there, which will restrict the use of "file_exist" logic, so for these type of situations....HOW CAN I COMPARE THE TWO FILE STRUCTURE TO GET THE SYNCHRONIZATION DONE AS PER REQUIREMENT??

EDITED

the requirement has to be a script, which I am going to need as a joomla component functionality.. please reply as per this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦途 2024-09-07 04:06:47

我建议为此使用 rsync。

I would suggest using rsync for this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文