Guest User

asdr

a guest
Mar 4th, 2013
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2.  
  3. //получаем байты, без округлений и прочей магии
  4. function getBytesLength($url) {
  5.  
  6.     $ch = curl_init($url);
  7.     curl_setopt($ch, CURLOPT_NOBODY, TRUE);//без туловка
  8.     curl_setopt($ch, CURLOPT_HEADER, TRUE);//только заголовки
  9.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  10.     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  11.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  12.     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
  13.  
  14.     $data = curl_exec($ch);
  15.     curl_close($ch);
  16.  
  17.     $lenght = false;
  18.  
  19.     if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
  20.         $lenght = (int) $matches[1];
  21.     }
  22.  
  23.     return $lenght;
  24. }
  25.  
  26.  
  27. function cast(){
  28.    
  29.     header('Content-Type: audio/mpeg');
  30.     header("Content-Disposition: attachment; filename=\"$name\"");
  31.    
  32.     $lenght = getBytesLength('http://cs4269.vk.me/u13852674/audios/980a620cae0c.mp3');
  33.     if ($lenght) {
  34.         header("Content-Length: $lenght");
  35.     }
  36.    
  37.     //эта функция будет вызываться в процессе выполнения курла (можно указать буффер)
  38.     function fTrans($ch, $string) {
  39.         $length = strlen($string);
  40.         echo $string;
  41.         return $length;
  42.     }
  43.    
  44.     $ch = curl_init($url);
  45.     curl_setopt($ch, CURLOPT_POSTFIELDS, FALSE);
  46.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  47.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  48.     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");    
  49.     curl_setopt($ch, CURLOPT_BUFFERSIZE, 512000); //в байтах
  50.     curl_setopt($ch, CURLOPT_WRITEFUNCTION, "fTrans");
  51.  
  52.     $data = curl_exec($ch);
  53.     curl_close($ch);
  54.     exit();
  55.    
  56. }
  57.  
  58.  
  59. #searchengines.ru
  60. #andygood
Advertisement
Add Comment
Please, Sign In to add comment