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 45 46 47 48 49 50 51 52 53 54 55 | <?php include "common.inc.php"; if (!($firstDate = getFirstDate())) die("Cannot complete diagnotics, cannot get first file date"); $currentDate = $firstDate; if (!($lastDate = getPreviousDate())) die("Cannot complete diagnotics, cannot get last file date"); $hashes = Array(); while ($currentDate != $lastDate) { $results = glob(DATA_DIR . "/" . $currentDate . "*"); if (sizeof($results) == 0) { echo "Error on $currentDate, no photo found for that date <br>"; } else if (sizeof($results) > 1) { echo "Error on $currentDate, more than one photo found for that date: <br>"; var_dump($results); echo "<br>"; } else { // normal day $fname = basename($results[0]); $fnParts = explode(".", $fname); if (sizeof($fnParts) < 3) { echo "Error on $currentDate, malformed file name {$fname} <br>"; } else { if (strtotime($currentDate) != strtotime($fnParts[0])) { echo "Error on $currentDate, file name {$fname} date does not match expected date <br>"; } if ($imgsize = getimagesize($results[0])) { if ($imgsize[0] < MIN_IMAGE_SIZE || $imgsize[1] < MIN_IMAGE_SIZE || $imgsize[0] != $imgsize[1]) { echo "Error on $currentDate, file name {$fname} is not large enough dimensions or non-square dimensions <br>"; } } else { echo "Error on $currentDate, file name {$fname} could not be opened as an image file. File may have been corrupted <br>"; } $hash = md5_file($results[0]); if ($hash != $fnParts[1]) { echo "Error on $currentDate, file name {$fname} hash does not match expected hash. File may have been corrupted or altered <br>"; } if (in_array($hash, array_keys($hashes))) { echo "Error on $currentDate, file {$fname} hash matches that of {$hashes[$hash]}. Files may be identitical duplicates of the same image <br>"; } $hashes[$hash] = $fname; if (sizeof($fnParts[2]) > 3 || ($fnParts[2] != "png" && $fnParts[2] != "jpg")) { echo "Error on $currentDate, file name {$fname} extension unexpected <br>"; } } } // go to next day $currentDate = date("Y-m-d", strtotime("+1 day", strtotime($currentDate))); } echo "Scanned files from $firstDate to $currentDate, no errors detected<br>"; ?> |