Skip to content

Instantly share code, notes, and snippets.

@anytizer
Created November 30, 2013 07:49
Show Gist options
  • Save anytizer/7716466 to your computer and use it in GitHub Desktop.
Save anytizer/7716466 to your computer and use it in GitHub Desktop.
Simulation of md5 hash of files in linux; helps to find out any files modified after you gave them to someone else. Calculates md5 hash of files under directory.
<?php
function md5_dir($path='/tmp')
{
global $counter;
global $skip_directories;
global $skip_extensions;
$handle = opendir($path);
while(false!==($file=readdir($handle)))
{
if(in_array($file, $skip_directories)) continue;
$full_path = $path.'/'.$file;
if(is_dir($full_path))
{
md5_dir($full_path);
}
else
{
$pathinfo = pathinfo($full_path);
#if(empty($pathinfo['extension'])) die('Sorry: '.$full_path);
if(empty($pathinfo['extension'])) continue;
if(in_array($pathinfo['extension'], $skip_extensions)) continue;
$data = array(
'count' => ++$counter,
'hash' => md5_file($full_path),
'date' => date('Y-m-d H:i:s', filemtime($full_path)),
'size' => number_format(filesize($full_path)),
'name' => str_replace(__ROOT__, '', $full_path),
);
echo implode("\t", $data), "\r\n";
#echo md5_file($full_path), "\t", $full_path, "\r\n";
} # if
} # while
}
header('Content-Type: text/plain');
$counter = 0;
$path = '/home/USER/public_html';
define('__ROOT__', $path);
$skip_directories = array('.', '..', '.svn', 'tmp', 'out');
$skip_extensions = array(
'txt',
'css',
'js',
'gif',
'jpg',
'png',
'JPG',
'jpeg',
'psd',
# 'php',
'md',
'ttf',
'xml',
'ico',
'htc',
'svg',
'map',
'htm',
'html',
'inc',
'properties',
'htaccess',
);
md5_dir($path);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment