turtle-wow-source-kinda/Dumps/Source Code/9 - Development_website_old/master/download.php

48 lines
936 B
PHP
Raw Normal View History

2024-08-06 16:06:40 +00:00
<?php
// file used in /watch download video feature
$file = $_REQUEST['file'];
if (!stristr($file, 'webm'))
return [];
$filename = basename($file);
$file = getcwd() . '/' . $file;
// inc downloads
$meta = json_decode(file_get_contents(str_replace('webm', 'meta', $file)), 1);
$meta['downloads']++;
file_put_contents(str_replace('webm', 'meta', $file), json_encode($meta));
header("Content-Type: video/webm");
header('Content-Transfer-Encoding: binary');
header("Content-Disposition: attachment; filename=$filename;");
$options = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$context = stream_context_create($options);
$handle = fopen($file, 'rb', false, $context);
ob_end_clean();
$chunkSize = 8 * 1024 * 1024;
ob_start();
while (!feof($handle)) {
$buffer = fread($handle, $chunkSize);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);