Skip to content

Instantly share code, notes, and snippets.

@Dynom
Created April 10, 2013 07:50
Show Gist options
  • Save Dynom/5352649 to your computer and use it in GitHub Desktop.
Save Dynom/5352649 to your computer and use it in GitHub Desktop.
Calculating a uniform distribution with respect to file-system limitation's (files/sub-directories per directory)
<?php
$networkEID = '0b3fe...a';
$fileEID = 'af4e0...f'
// e.g.: 19c679c10770acc216c26045cc5406c8155
$largeNumber = hash("sha1", $fileEID);
// Converting from base-16 to base-13
$hash = gmp_strval(gmp_init($largeNumber, 16), 13);
// Resulting path: /mnt/san/b1/34/c11b06b89859a226b11634c5901b9bc54/Foo.pdf
$pathToSave = STORAGE_ROOT .
$networkEID .
substr($hash, 0, 2) . DIRECTORY_SEPARATOR .
substr($hash, 2, 2) . DIRECTORY_SEPARATOR .
substr($hash, 4, 2) . DIRECTORY_SEPARATOR .
substr($hash, 6); // Filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment