#!/usr/bin/php
<?

// Polyfill
// Fill a volume with many small files

$base = "/Volumes/Polyfill";
$total = 10000;

for ($i = 0; $i < $total; $i++) {

	$stamp = md5(microtime());
	$levels = array();
	$levels[] = substr($stamp,0,2);
	$levels[] = substr($stamp,2,2);
	$levels[] = substr($stamp,4,2);
	$levels[] = substr($stamp,6,2);
	$levels[] = substr($stamp,8,2);
	$levels[] = substr($stamp,10,2);
	$dest = $base."/".implode("/",$levels)."/".$stamp;
	
	$check = array();
	$check[] = $base."/".$levels[0];
	$check[] = $base."/".$levels[0]."/".$levels[1];
	$check[] = $base."/".$levels[0]."/".$levels[1]."/".$levels[2];
	$check[] = $base."/".$levels[0]."/".$levels[1]."/".$levels[2]."/".$levels[3];
	$check[] = $base."/".$levels[0]."/".$levels[1]."/".$levels[2]."/".$levels[3]."/".$levels[4];
	$check[] = $base."/".$levels[0]."/".$levels[1]."/".$levels[2]."/".$levels[3]."/".$levels[4]."/".$levels[5];

	foreach ($check as $dir) {
		echo "check ".$dir."\n";
		if (!file_exists($dir)) {
			mkdir($dir);
			}
		}
	
	echo $dest."\n";
	copy("test.jpg",$dest.".jpg");
	//file_put_contents($dest,serialize($levels));
	}

?>