Skip to content

Instantly share code, notes, and snippets.

@NanoDano
Created August 6, 2020 01:36
Show Gist options
  • Save NanoDano/58e0eb7b63c36e28a1e8f475b601f74c to your computer and use it in GitHub Desktop.
Save NanoDano/58e0eb7b63c36e28a1e8f475b601f74c to your computer and use it in GitHub Desktop.
PHP list & serve gzipped files from dir
<?php
/**
* Given a directory full of gzipped AVI files,
* outpu a JSON array with the list of zipped video files in the dir.
*
* If a GET query param is provided for `file` then that specific
* file is returned, uncompressed, with the .gz extension removed
*/
if (isset($_GET['file'])) {
if (!file_exists($_GET['file'])) {
http_response_code(404);
exit;
}
header('Content-Type: video/x-msvideo');
header('Content-Disposition: attachment; filename=' . substr($_GET['file'], 0, -3));
echo file_get_contents("compress.zlib://" . $_GET['file']);
exit;
}
$zipped_videos = glob('*.avi.gz');
echo json_encode($zipped_videos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment