【发布时间】:2015-09-21 20:13:46
【问题描述】:
所以我有一个目录,我在将每个文件的哈希写入/添加到文本文档时获取目录中所有文件的哈希,我在文档中一直以相同的哈希结束 10-100 次,我无法弄清楚为什么 php 一直这样做。
任何人都可以在 windows 上运行它,以亲自查看脚本执行的 certutil 内置于 windows 中,因此它可以在任何 windows 机器上运行。
<?php
$file_path = 'C:\Users\C0n\Desktop\hash-banned.txt';
foreach (glob("R:\backup\Videos\*") as $filename) {
exec('CertUtil -hashfile "'.$filename.'" SHA1', $response);
$str = str_replace(' ', '', $response[1]);
$find_hashes = file($file_path,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($find_hashes as $n1) {
if($str == $n1) {
echo "duplicate detected";
break;
}
echo "Hash does not exist so adding " . $str;
//hash not found so add to file
//if hash string is not empty then write to file
if ($str != "") {
file_put_contents($file_path, $str . "\n", FILE_APPEND);
}
}
}
?>
【问题讨论】:
标签: php loops duplicates