I had a code that worked, here:
if (isset($_GET['file']) && isset($_GET['name']))
{
$file = base64_decode($_REQUEST['file']);
$ch = curl_init($file);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
curl_close($ch);
if (preg_match('/Content-Length: (\d+)/', $data, $matches))
{
// Contains file size in bytes
$contentLength = (int)$matches[1];
}
header("Content-type: application/x-file-to-save");
header("Content-Disposition: attachment; filename=".$_REQUEST['name']);
header('Content-Length: ' . $contentLength);
header('Content-Transfer-Encoding: binary');
@readfile($file);
}
And than I changed my server to a differenf host providor, and the code stoped working. When I download from chrome it just keeps loading and loading,
but when I download from a download manager like IDM than it gets the correct name and size, but when I press start it makes an error that says something about not supporting resuming or something…
Again, the code worked when I used a different providor.
It might be errors which are outputted before
readfile()useob_clean();to remove any output beforeflush();
readfile