Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Niedziałające wznawianie pobierania, a na localu działa
elemek
post 27.08.2008, 13:49:49
Post #1





Grupa: Zarejestrowani
Postów: 71
Pomógł: 24
Dołączył: 14.08.2008

Ostrzeżenie: (0%)
-----


Witam,
Mam taki problem, po wgraniu witryny na serwer dedykowany przestało działać wznawianie pobierania (przeglądarka w ogóle nie "widzi" rozmiaru pobieranego pliku). Wszystko świetnie działa spod WAMPa na localhoście. Może któryś z szanownych forumowiczów spotkał się już z takim problemem i zna rozwiązanie?

Tutaj akcja odpowiedzialna za pobieranie pliku:

  1. <?php
  2. function downloadAction() {
  3. $id = (int)$this->_getParam('id', -1);
  4. if (isset($_SESSION['browsing'])) {
  5. $dd = $this->soft->getDownloadDetails($id);
  6. if (($filename = $dd['local_path']) != '') {
  7. $path = Zend_Registry::get('config')->software->root."/$id/$filename";
  8. $date = date("D, d M y H:i:s e", filemtime($path));
  9. $size = filesize($path);
  10. $filename = preg_replace('/^(.*).(.+)$/', '$1_[www.example.com].$2', $filename);
  11.  
  12. header("Content-Type: application/octet-stream");
  13. header('Content-Transfer-Encoding: binary'); 
  14. header("Content-Disposition: attachment; filename=\"$filename\";");
  15. header("Last-Modified: $date");
  16.  
  17.  if (isset($_SERVER['HTTP_RANGE']) && preg_match('/^bytes=(d+)-(d*)$/i', $_SERVER['HTTP_RANGE'], $matches) == 1) {
  18. $data_start = $matches[1];
  19. if ($matches[2] != '') {
  20. $data_stop = $matches[2];
  21. } else {
  22. $data_stop = $size - 1;
  23. }
  24. $len = $data_stop - $data_start + 1;
  25. header('HTTP/1.1 206 Partial Content');
  26. header('Accept-Ranges: bytes');
  27. header("Content-Range: bytes $data_start-$data_stop/$size");
  28. header("Content-Length: $len");
  29.  
  30. } else {
  31. header("Content-Length: $size");
  32. $data_start = 0;
  33. $data_stop = $size - 1;
  34. $len = $data_stop - $data_start + 1;
  35. }
  36.  
  37.  
  38. $fp = fopen($path, "rb");
  39. fseek($fp, $data_start);
  40. $chunk = 8192*1024; // MiB
  41. while ($len > 0) {
  42. if ($len > $chunk) {
  43. $len -= $chunk;
  44. echo fread($fp, $chunk);
  45. } else {
  46. echo fread($fp, $len);
  47. break;
  48. }
  49. }
  50. fclose($fp);
  51. $this->soft->hitDownloadCount($id);
  52. } else {
  53. header("Location: {$dd['download_link']}");
  54. }
  55. } else {
  56. header("Location: /details,$id.html");
  57. }
  58. die(0);
  59. }
  60. ?>


--------------------
Rzecz trudną rozbijam na kilka łatwiejszych :)
Pomogłem? Kliknij Pomógł.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 16.04.2024 - 13:07