我正在编写一个脚本 PHP 脚本,它每 24 小时创建一个所选目录的所有文件的报告。我想将最新报告与以前的报告进行比较,以检测文件的任何编辑(通过比较 md5 哈希)、文件的删除和文件的创建。我将两个报告的数据放在两个单独的数组中。据我所知,我将不得不使用 array_diff 函数。我如何:A) 将其与多维数组一起使用,B) 如果差异是编辑、删除或创建,则使用标签。
数据示例:
新报告:
Array
(
[0] => Array
(
[file] => newhotfolder.gif
[path] => images/newhotfolder.gif
[type] => gif
[size] => 1074
[md5] => 123812asdkbqw98eqw80hasdas234234
)
[1] => Array
(
[file] => image.gif
[path] => images/attachtypes/image.gif
[type] => gif
[size] => 625
[md5] => 7bbb66e191688a86b6f42a03bd412a6b
)
[2] => Array
(
[file] => header.gif
[path] => images/attachtypes/header.gif
[type] => gif
[size] => 625
[md5] => 71291239asskf9320234kasjd8239393
)
)
旧报告:
Array
(
[0] => Array
(
[file] => newhotfolder.gif
[path] => images/newhotfolder.gif
[type] => gif
[size] => 1074
[md5] => 8375h5910423aadbef67189c6b687ff51c
)
[1] => Array
(
[file] => image.gif
[path] => images/attachtypes/image.gif
[type] => gif
[size] => 625
[md5] => 7bbb66e191688a86b6f42a03bd412a6b
)
[2] => Array
(
[file] => footer.gif
[path] => images/attachtypes/footer.gif
[type] => gif
[size] => 625
[md5] => 1223819asndnasdn2213123nasd921
)
)
该函数必须能够检测到“newhotfolder.gif”的 md5 散列已更改,文件“footer.gif”已删除以及“header.gif”已添加。也许像这样返回第三个数组?:
比较:
Array
(
[0] => Array
(
[file] => newhotfolder.gif
[path] => images/newhotfolder.gif
[type] => gif
[size] => 1074
[md5] => 8375h5910423aadbef67189c6b687ff51c
[status] => edited
)
[1] => Array
(
[file] => image.gif
[path] => images/attachtypes/image.gif
[type] => gif
[size] => 625
[md5] => 7bbb66e191688a86b6f42a03bd412a6b
[status] => same
)
[2] => Array
(
[file] => footer.gif
[path] => images/attachtypes/footer.gif
[type] => gif
[size] => 625
[md5] => 1223819asndnasdn2213123nasd921
[status] => deleted
)
[3] => Array
(
[file] => header.gif
[path] => images/attachtypes/header.gif
[type] => gif
[size] => 625
[md5] => 71291239asskf9320234kasjd8239393
[status] => new
)
)