First I would like to apologize for my stupidity…
I need to provide a download of large videofiles from a webpage.
The files are between 4 and 20 gb.
Question: What is the right way to enable such a download?
I tried some ways but the download always aborted or did not work
First try was this because I have used it for some smaller files in the past – but in this case the download stopped at 1 GB
header("Content-Type: $type");
header("Content-Disposition: attachment; filename="$fileName"");
readfile($dir.$file);
I tried also to download it chunk by chunk. The browser started the download correctly but crashed after a short time.
$chunksize = 5 * (1024 * 1024); //5 MB (= 5 242 880 bytes) per one chunk of file.
if(file_exists($filename))
{
set_time_limit(10800);
$size = intval(sprintf("%u", filesize($filename)));
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.$size);
header('Content-Disposition: attachment;filename="'.basename($filename).'"');
if($size > $chunksize)
{
$handle = fopen($filename, 'rb');
while (!feof($handle))
{
print(@fread($handle, $chunksize));
ob_flush();
flush();
}
fclose($handle);
}
else readfile($filename);
exit;
}
else echo 'File "'.$filename.'" does not exist!';*/
Last try was X-Sendfile, but I think the webhosting Server does not support it, because it does not work?
if (file_exists($fileonserver))
{
// send the right headers
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Content-type: ' . $type);
header('Content-Length: ' . filesize($fileonserver));
header('X-Sendfile: ' . $fileonserver);
//exit;
}
else
{
die('File loading failed.');
}
user24772931 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.