layer-8/app/downloader.php

32 lines
946 B
PHP
Executable File

<?php
function downloader($path, $mm_type="application/octet-stream") {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " . filesize($path) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
ob_clean();
flush();
$chunk_size = 8192;
$handle = fopen($path, 'rb');
if ($handle) {
while (!feof($handle)) {
echo fread($handle, $chunk_size);
flush();
}
fclose($handle);
}
die(); // TODO: Fix file being empty ._.
}
//https://www.kavoir.com/2009/05/php-hide-the-real-file-url-and-provide-download-via-a-php-script.html