Проверка проблемы Размер файла удаленного URL
Суть следующего - ссылка, по которой мы получаем другую ссылку на файл
Скажем так ...
http://poiskm.ru/index.php/get/strack/679ca5/2dc1d0/f?download.mp3
-
http://musicbox.uz/download.php?file=http://poiskm.ru/index.php/get/strack/679ca5/2dc1d0/f?download.mp3
Помоги мне !!
Код:
$file=$_GET['file'];
$ch = curl_init($file);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here)
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {}
$contentLength = '0';
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
$contentLength = (int)$matches[1];
}
$url = $file;
$file_name = basename($url);
//lets be nice to the user and replace the spaces with happy things
$file_name=str_replace("%20","_",$file_name);
//this is the filename we get to play with
$infile = $url;
$file_name = stristr ($infile,basename ($infile));
header( "Pragma: public" ); // required
header( "Expires: 0" );
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public"); // required for certain browsers
header("Content-Type: application/mp3");
header('Content-Disposition: attachment; filename="[www.MusicBox.uz]'.urldecode($file_name).'"');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$contentLength);
//header('Connection: close');
// The File source is in .mp3 originally
//This is the file that we are downloading
readfile(stripslashes($file));