-
-
Save Kambaa/219c18be7078ac96e54e91f93c1b63f3 to your computer and use it in GitHub Desktop.
AppCache generator #php #appcache
This file contains 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 | |
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