Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Created May 5, 2013 15:52
Show Gist options
  • Save jrobinsonc/5521205 to your computer and use it in GitHub Desktop.
Save jrobinsonc/5521205 to your computer and use it in GitHub Desktop.
AppCache generator #php #appcache
<?php
function get_dir($dir)
{
$files = array();
$exclude = array('.', '..', 'appcache.php', '.git', '.gitignore', 'nbproject', 'TODO', 'README.md', 'cache.manifest');
foreach (scandir($dir) as $item)
{
if (in_array($item, $exclude)) continue;
//---------------------------------------------------
$item_full = realpath("{$dir}/{$item}");
if (is_file($item_full))
{
$files[] = $item_full;
}
elseif (is_dir($item_full))
{
$files = array_merge($files, get_dir($item_full));
}
}
return $files;
}
$dir = __DIR__;
$h = fopen("{$dir}/cache.manifest", 'w');
fwrite($h, 'CACHE MANIFEST' . "\n\n");
fwrite($h, '# Time: '. date('r') . "\n\n");
fwrite($h, 'CACHE:' . "\n");
foreach(get_dir($dir) as $item)
{
$item = ltrim(str_replace('\\', '/', str_replace($dir, '', $item)), '/');
fwrite($h, $item . "\n");
}
fwrite($h, "\n" . 'NETWORK:' . "\n");
fwrite($h, '*');
fclose($h);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment