Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //получаем байты, без округлений и прочей магии
- function getBytesLength($url) {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_NOBODY, TRUE);//без туловка
- curl_setopt($ch, CURLOPT_HEADER, TRUE);//только заголовки
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
- $data = curl_exec($ch);
- curl_close($ch);
- $lenght = false;
- if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
- $lenght = (int) $matches[1];
- }
- return $lenght;
- }
- function cast(){
- header('Content-Type: audio/mpeg');
- header("Content-Disposition: attachment; filename=\"$name\"");
- $lenght = getBytesLength('http://cs4269.vk.me/u13852674/audios/980a620cae0c.mp3');
- if ($lenght) {
- header("Content-Length: $lenght");
- }
- //эта функция будет вызываться в процессе выполнения курла (можно указать буффер)
- function fTrans($ch, $string) {
- $length = strlen($string);
- echo $string;
- return $length;
- }
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POSTFIELDS, FALSE);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
- curl_setopt($ch, CURLOPT_BUFFERSIZE, 512000); //в байтах
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, "fTrans");
- $data = curl_exec($ch);
- curl_close($ch);
- exit();
- }
- #searchengines.ru
- #andygood
Advertisement
Add Comment
Please, Sign In to add comment