3
I’m having some problems with the process of script
down below.
Literally it is making the download very slow, and this when the download process does not occur to fall or restart from scratch.
Is there any way to fix this, so that the download is done normally, with a more effective process?
The downloadable files reach at most 350MB
.
Updating: Someone would know to tell me what the problem is I’ve already changed in php.ini the parameter settings for memory_limit
, post_max_size
, upload_max_filesize
and max_execution_time
and even then the download process remains slow.
<?php
$file = 'http://thumb.mais.uol.com.br/15540367.mp4';
download($file,314572800);
function download($file,$chunks){
set_time_limit(0);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='.basename($file));
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
header('Pragma: public');
$size = get_size($file);
header('Content-Length: '.$size);
$i = 0;
while($i<=$size){
get_chunk($file,(($i==0)?$i:$i+1),((($i+$chunks)>$size)?$size:$i+$chunks));
$i = ($i+$chunks);
}
}
function chunk($ch, $str) {
print($str);
return strlen($str);
}
function get_chunk($file,$start,$end){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RANGE, $start.'-'.$end);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'chunk');
$result = curl_exec($ch);
curl_close($ch);
}
function get_size($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
return intval($size);
}
?>
@Striffer, after the downloaded file to your server, just send the file to your client, via download.
– Diego B. Sousa