<?php 
header('Content-Type: text/cache-manifest');

global $prefix;
$u = $_SERVER['REQUEST_URI'];
#$prefix  = substr($u, 0, strrpos( $u,'/' ));
#$prefixR = substr($u, 0, strpos( $u,'/iphone' ));
$prefix  = '../';
$prefixR = '';

function ReadFolderDirectory($dir = "/", $extArr)
    {
		global $prefix;
        static $hashes = '';
        
		$home = substr( dirname(__FILE__), 0, strrpos(dirname(__FILE__),'/') );
				
        if($handler = opendir($home."/".$dir)) {
            while (($sub = readdir($handler)) !== FALSE) {
                if ($sub != "." && $sub != ".." && $sub != "Thumb.db") {

                    if(is_file($home."/".$dir."/".$sub)) {

						$ext = strtolower(end(explode(".", $sub)));
                        
						if( in_array($ext, $extArr ) ){
							#echo $prefixR.$dir."/".$sub."\n";
							echo $prefix.$dir."/".$sub."\n";
							$hashes .= md5_file($home."/".$dir."/".$sub);
	  					}
                        
                    }elseif(is_dir($home."/".$dir."/".$sub)){
                        ReadFolderDirectory($dir."/".$sub, $extArr);
                    }
                }
            }
            closedir($handler);
        }
        return $hashes;
    }

?>
CACHE MANIFEST
offline.html
../js/jquery.js
../img/apple-touch-icon.png
../img/grid-blue.gif
../img/default-photo-on.jpg
<?php
	#$hashes  = ReadFolderDirectory('iphone', array('js','css','jpg','png','gif'));
	#$hashes .= ReadFolderDirectory('photos', array('jpg','png','gif'));
?>

#NETWORK:
<?php
	#$hashes .= ReadFolderDirectory('iphone', array('php'));
	#$hashes .= ReadFolderDirectory('inc', array('php'));
?>

FALLBACK:
<?=$prefix?>img/ <?=$prefix?>img/grid-blue.gif
<?=$prefix?>photos/ <?=$prefix?>img/default-photo-on.jpg
# <?=$prefixR?> <?=$prefixR?>offline.html

<?php
die ("# Hash " . md5($hashes) . "\n");
//die ("# Hash: " . md5($hashes).rand(1,rand(100,500)) . "\n");
?>