Проблемы проверить размер файл удаленного сервераУдаленного размера файла с завитком
Сущности ниже приводится ссылка на которую мы получаем другую ссылку на файл
Давайте говорить ... 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));
Связанный: [Как получить размер файла удаленно сохраненного изображения? (php)] (http://stackoverflow.com/questions/3894653/how-to-get-the-file-size-of-a-remotely-stored-image-php) – hakre