1. <?php
  2. //error_reporting(0);
  3.  
  4.  
  5.  
  6. $download = 'http://s52.jakisadres/download/128265050_255103_1308449084_0_9241315151731';
  7.  
  8.  
  9. $remoteFile = $download;
  10. $ch = curl_init($remoteFile);
  11. curl_setopt($ch, CURLOPT_NOBODY, true);
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  13. curl_setopt($ch, CURLOPT_HEADER, true);
  14. $data = curl_exec($ch);
  15. curl_close($ch);
  16. if ($data === false) {
  17. echo 'Plik wygasł!';
  18. }
  19.  
  20. if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) {
  21. $status = (int)$matches[1];
  22. }
  23. if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
  24. $waga = (int)$matches[1];
  25. }
  26. if (preg_match('/filename="(.*)"/', $data, $wynik)){
  27. $nazwa = trim($wynik[1]);
  28. }
  29. //print_r($waga);
  30.  
  31.  
  32. $filename = basename($nazwa);
  33. $file_extension = strtolower(substr(strrchr($filename,"."),1));
  34.  
  35. switch( $file_extension ) {
  36. case "exe":
  37. $ctype="application/octet-stream";
  38. break;
  39. case "rar":
  40. $ctype="application/x-rar-compressed";
  41. break;
  42. case "zip":
  43. $ctype="application/zip";
  44. break;
  45. case "mp3":
  46. $ctype="audio/mpeg";
  47. break;
  48. case "mpg":
  49. $ctype="video/mpeg";
  50. break;
  51. case "avi":
  52. $ctype="video/x-msvideo";
  53. break;
  54.  
  55.  
  56. case "php":
  57. case "htm":
  58. case "html":
  59. case "txt":
  60. die("<b>Bład plik ". $file_extension ." !</b>");
  61. break;
  62. default:
  63. $ctype="application/force-download";
  64. }
  65.  
  66.  
  67. header("Cache-Control:");
  68. header("Cache-Control: public");
  69. header("Content-Type: $ctype");
  70.  
  71. $filespaces = str_replace("_", " ", $filename);
  72.  
  73.  
  74. $header='Content-Disposition: attachment; filename='.$filespaces;
  75. header($header);
  76.  
  77.  
  78. header("Accept-Ranges: bytes");
  79.  
  80. $size = $waga;
  81.  
  82. if(isset($_SERVER['HTTP_RANGE'])) {
  83.  
  84.  
  85. $seek_range = substr($_SERVER['HTTP_RANGE'] , 6);
  86. $range = explode( '-', $seek_range);
  87. if($range[0] > 0) { $seek_start = intval($range[0]); }
  88. if($range[1] > 0) { $seek_end = intval($range[1]); }
  89.  
  90. header("HTTP/1.1 206 Partial Content");
  91. header("Content-Length: " . ($seek_end - $seek_start + 1));
  92. header("Content-Range: bytes $seek_start-$seek_end/$size");
  93. } else {
  94. header("Content-Range: bytes 0-$seek_end/$size");
  95. header("Content-Length: $waga");
  96. }
  97.  
  98. $ch = curl_init();
  99. curl_setopt($ch, CURLOPT_URL, $download);
  100. curl_exec($ch);
  101. curl_close($ch);
  102.  
  103. ?>



niestety niewiem czemu nie wznawia mi połączenie jak zerwie się trzeba potem od nowa pobierać