Просмотр файла engine/classes/files.class.php

Размер файла: 2.87Kb
  1. <?
  2. /*
  3. * Класс для работы с файлами
  4. */
  5.  
  6. class files {
  7.  
  8. public function player($name,$param,$style,$file) {
  9. $player = '<object '.$param.'>';
  10. $player .= '<param name="allowFullScreen" value="true" />';
  11. $player .= '<param name="allowScriptAccess" value="always" />';
  12. $player .= '<param name="wmode" value="transparent" />';
  13. $player .= '<param name="movie" value="'.$name.'" />';
  14. $player .= '<param name="flashvars" value="st='.$style.'&amp;file='.$file.'" />';
  15. $player .= '<embed src="uppod.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" flashvars="st='.$style.'&amp;file='.$file.'" '.$param.'>';
  16. $player .= '</embed>';
  17. $player .= ' </object>';
  18. return $player;
  19. }
  20. //”ункциЯя скачивание файлов
  21. public function downloadFile($filename, $name, $mimetype = 'application/octet-stream')
  22. {
  23. if (!file_exists($filename))
  24. die('Файл не найден');
  25. $from = $to = 0;
  26. $cr = null;
  27. if (isset($_SERVER['HTTP_RANGE'])) {
  28. $range = substr($_SERVER['HTTP_RANGE'], strpos($_SERVER['HTTP_RANGE'], '=') + 1);
  29. $from = strtok($range, '-');
  30. $to = strtok('/');
  31. if ($to > 0)
  32. ++$to;
  33. if ($to)
  34. $to -= $from;
  35. header('HTTP/1.1 206 Partial Content');
  36. $cr = 'Content-Range: bytes ' . $from . '-' . (($to) ? ($to . '/' . $to + 1) :
  37. filesize($filename));
  38. } else
  39. header('HTTP/1.1 200 Ok');
  40. $etag = md5($filename);
  41. $etag = substr($etag, 0, 8) . '-' . substr($etag, 8, 7) . '-' . substr($etag, 15,
  42. 8);
  43. header('ETag: "' . $etag . '"');
  44. header('Accept-Ranges: bytes');
  45. header('Content-Length: ' . (filesize($filename) - $to + $from));
  46. if ($cr)
  47. header($cr);
  48. header('Connection: close');
  49. header('Content-Type: ' . $mimetype);
  50. header('Last-Modified: ' . gmdate('r', filemtime($filename)));
  51. $f = fopen($filename, 'r');
  52. header('Content-Disposition: attachment; filename="' . $name . '";');
  53. if ($from)
  54. fseek($f, $from, SEEK_SET);
  55. if (!isset($to) or empty($to)) {
  56. $size = filesize($filename) - $from;
  57. } else {
  58. $size = $to;
  59. }
  60. $downloaded = 0;
  61. while (!feof($f) and !connection_status() and ($downloaded < $size)) {
  62. echo fread($f, 512000);
  63. $downloaded += 512000;
  64. ob_flush();
  65. flush();
  66. }
  67. fclose($f);
  68. }
  69.  
  70.  
  71.  
  72. }
  73.  
  74.  
  75.  
  76. ?>