Skip to content

Instantly share code, notes, and snippets.

@tx2z
Last active December 5, 2017 01:26
Show Gist options
  • Save tx2z/5249812 to your computer and use it in GitHub Desktop.
Save tx2z/5249812 to your computer and use it in GitHub Desktop.
<?php
// Add the correct Content-Type for the cache manifest
header('Content-Type: text/cache-manifest');
// Write the first line
echo "CACHE MANIFEST\n";
// Initialize the $hashes string
$hashes = "";
function create_manifest($folder) {
$dir = new RecursiveDirectoryIterator($folder);
// Iterate through all the files/folders in the current directory
foreach (new RecursiveIteratorIterator($dir) as $file) {
$info = pathinfo($file);
// If the object is a file
// and it's not called manifest.php (this file),
// and it's not a dotfile, add it to the list
if ($file -> IsFile() && $file != "./manifest.php" && substr($file -> getFilename(), 0, 1) != ".") {
// Replace spaces with %20 or it will break
echo str_replace(' ', '%20', $file) . "\n";
// Add this file's hash to the $hashes string
$hashes .= md5_file($file);
}
}
}
create_manifest(".");
// Write the $hashes string
echo "# Hash: " . md5($hashes) . "\n";
?>
<?php
// Add the correct Content-Type for the cache manifest
header('Content-Type: text/cache-manifest');
// Write the first line
echo "CACHE MANIFEST\n";
?>
<?php
function create_manifest($folder) {
$dir = new RecursiveDirectoryIterator($folder);
// Iterate through all the files/folders in the current directory
foreach (new RecursiveIteratorIterator($dir) as $file) {
$info = pathinfo($file);
// If the object is a file
// and it's not called manifest.php (this file),
// and it's not a dotfile, add it to the list
if ($file -> IsFile() && $file != "./manifest.php" && substr($file -> getFilename(), 0, 1) != ".") {
// Replace spaces with %20 or it will break
echo str_replace(' ', '%20', $file) . "\n";
// Add this file's hash to the $hashes string
$hashes .= md5_file($file);
}
}
}
?>
<?php
create_manifest(".");
?>
<?php
// Write the $hashes string
echo "# Hash: " . md5($hashes) . "\n";
?>
<!DOCTYPE html>
<html manifest="manifest.php">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment