-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_sha512.php
44 lines (36 loc) · 1.3 KB
/
create_sha512.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
include('./config.php');
// sql to truncate table
$sql = "truncate table file_sha512";
if ($conn->query($sql) === TRUE) {
echo "Table Truncated </br>";
} else {
echo "Error truncating table: " . $conn->error;
}
function getDirContents($dir, $filter = '', &$results = array()) {
$files = scandir($dir);
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
if(empty($filter) || preg_match($filter, $path)) $results[] = $path;
} elseif($value != "." && $value != "..") {
getDirContents($path, $filter, $results);
}
}
return $results;
}
$myarray=getDirContents($web_path, '/\.php$/');
foreach ($myarray as $path) {
$filename=basename($path);
$sha512_hash=hash_file($hash_function, $path,false);
$Date_Time=date("Y-m-d H:i:s");
echo "file: " . $filename . " sha512: " . $sha512_hash . " Date: " . $Date_Time . "<br>";
$sql = "INSERT INTO file_sha512 (File_Name, Source_File_Path, sha512, Date_Time) VALUES ('$filename', '$path', '$sha512_hash', '$Date_Time')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>