Last active
April 6, 2019 06:13
-
-
Save ryanbekabe/5b13eaed7e9ca33af5f9e32ba853301f to your computer and use it in GitHub Desktop.
PHP Hash MD5 SHA256 File Recursive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//[email protected] | |
if(isset($_GET['recursivehash']) AND isset($_GET['rest'])) | |
{ | |
//https://stackoverflow.com/questions/34190464/php-scandir-recursively | |
//https://stackoverflow.com/questions/15687363/php-access-global-variable-in-function | |
//global $varrest; | |
date_default_timezone_set('Asia/Jakarta'); | |
$waktupengiriman=date("YmdHi"); | |
$varpathtorecursive = ($_GET['recursivehash']); | |
$varrest = $_GET['rest']."-".$waktupengiriman; | |
function scandir_rec($root) | |
{ | |
global $varrest; | |
// if root is a file | |
if (is_file($root)) { | |
echo '<li>' . basename($root) . '</li>'; | |
return; | |
} | |
if (!is_dir($root)) { | |
return; | |
} | |
$dirs = scandir($root); | |
foreach ($dirs as $dir) { | |
if ($dir == '.' || $dir == '..') { | |
continue; | |
} | |
$path = $root . '/' . $dir; | |
if (is_file($path)) { | |
// if file, create list item tag, and done. | |
$varmd5=hash_file('md5',$path); | |
$varsha256=hash_file('sha256',$path); | |
$varsize=filesize($path); | |
$vartipe=filetype($path); | |
echo '<li>file MD5 : '.$varmd5.' - SHA256 : '.$varsha256.' - path - '.$path.' :' . $dir . '</li>'; | |
//mysql_query("INSERT INTO ryanfilelog(id, filename, md5, sha256, filesize, filetype, rest) VALUES(NULL,'$dir','$varmd5','$varsha256','$varsize','$vartipe','$varrest')"); | |
} else if (is_dir($path)) { | |
// if dir, create list item with sub ul tag | |
echo '<li>'; | |
echo '<label>' . $dir . '</label>'; | |
echo '<ul>'; | |
scandir_rec($path); // <--- then recursion | |
echo '</ul>'; | |
echo '</li>'; | |
} | |
} | |
} | |
// init call | |
$rootDir = $varpathtorecursive; | |
echo '<ul>'; | |
scandir_rec($rootDir); | |
echo '</ul>'; | |
die; | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment