Remove the Content-Type: application/json HTTP header when retrieving urls.txt inside a .zip

This commit is contained in:
Benjamin Loison 2023-02-09 02:07:10 +01:00
parent 01aac3f66e
commit ea604cce40
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -7,13 +7,23 @@
} }
} }
if (!function_exists('str_ends_with')) {
function str_ends_with($haystack, $needle)
{
$length = strlen($needle);
return $length > 0 ? substr($haystack, -$length) === $needle : true;
}
}
$uri = $_SERVER['REQUEST_URI']; $uri = $_SERVER['REQUEST_URI'];
$uri = str_replace('/channels/', '', $uri); $uri = str_replace('/channels/', '', $uri);
$prefix = '/mnt/HDD0/YouTube_captions_search_engine/channels/'; $prefix = '/mnt/HDD0/YouTube_captions_search_engine/channels/';
if (str_contains($uri, '/')) { if (str_contains($uri, '/')) {
$uri = str_replace('/', '#', $uri); $uri = str_replace('/', '#', $uri);
$uri = $prefix . $uri; $uri = $prefix . $uri;
if (str_ends_with($uri, '.json')) {
header('Content-Type: application/json; charset=UTF-8'); header('Content-Type: application/json; charset=UTF-8');
}
echo file_get_contents("zip://$uri"); echo file_get_contents("zip://$uri");
} else { } else {
$uri = $prefix . $uri; $uri = $prefix . $uri;