download.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. class download_c extends Control
  3. {
  4. function __construct()
  5. {
  6. parent::Control();
  7. $this->load_model("upfile");
  8. }
  9. function download_c()
  10. {
  11. $this->__construct();
  12. }
  13. function index_f()
  14. {
  15. $id = $this->trans_lib->int("id");
  16. if(!$id)
  17. {
  18. error($this->lang["download_error"],$this->url());
  19. }
  20. $rs = $this->upfile_m->get_one($id);
  21. //执行下载操作
  22. if(!file_exists(ROOT.$rs["filename"]) || !$rs["filename"] || !is_file(ROOT.$rs["filename"]))
  23. {
  24. error($this->lang["download_empty"],$this->url());
  25. }
  26. $filesize = filesize(ROOT.$rs["filename"]);
  27. if(!$rs["title"]) $rs["title"] = $rs["filename"];
  28. $tmpname = str_replace(".".$rs["ftype"],"",$rs["title"]);
  29. $tmpname = $tmpname.".".$rs["ftype"];
  30. ob_end_clean();
  31. header("Date: ".gmdate("D, d M Y H:i:s", $rs["postdate"])." GMT");
  32. header("Last-Modified: ".gmdate("D, d M Y H:i:s", $rs["postdate"])." GMT");
  33. header("Content-Encoding: none");
  34. header("Content-Disposition: attachment; filename=".rawurlencode($tmpname));
  35. header("Content-Length: ".$filesize);
  36. header("Accept-Ranges: bytes");
  37. readfile($rs["filename"]);
  38. flush();
  39. ob_flush();
  40. }
  41. }
  42. ?>