Last active
April 4, 2017 10:18
-
-
Save lrepolho/ab522c66c9842642d281956c5a83b692 to your computer and use it in GitHub Desktop.
Set filenames as it's equivalent SHA256
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 | |
// usage: php renamefiles.php /path/to/dir | |
$photosDir = $_SERVER['argv']['1']; | |
$files = scandir($photosDir); | |
foreach ($files as $file) { | |
if ($file == '.' || $file == '..') { | |
continue; | |
} | |
$oldFile = "$photosDir$file"; | |
$extension = pathinfo($oldFile, PATHINFO_EXTENSION); | |
$hash = hash_file('sha256', $oldFile); | |
$newFile = "$photosDir$hash.$extension"; | |
rename($oldFile, $newFile); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment