I have the following PHP code which concerns the download methods for my website. I am trying to rate-limit the download speed to something specific since it is currently being abused and milked by download managers.
I am not experienced in coding, unfortunately.
public function download(
$file,
$filename,
$file_size,
$content_type,
$disposition = 'inline',
$android = false
) {
// Gzip enabled may set the wrong file size.
if (function_exists('apache_setenv')) {
@apache_setenv('no-gzip', 1);
}
if (ini_get('zlib.output_compression')) {
@ini_set('zlib.output_compression', 'Off');
}
@set_time_limit(0);
session_write_close();
header("Content-Length: ".$file_size);
if ($android) {
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
} else {
header("Content-Type: $content_type");
header("Content-Disposition: $disposition; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Expires: -1");
}
if (ob_get_level()) {
ob_end_clean();
}
readfile($file);
return true;
}