Home >Backend Development >PHP Tutorial >Query and download word directly from the database

Query and download word directly from the database

WBOY
WBOYOriginal
2016-07-25 08:49:37861browse
  1. function save($word_name)
  2. {
  3. echo "";
  4. $data = ob_get_contents();
  5. ob_end_clean();
  6. $this->wirtefile ($word_name,$data);
  7. }
  8. function wirtefile ($word_name,$data)
  9. {
  10. $path = 'public/uploads/'.$word_name;
  11. $file = fopen($path,"wd");
  12. fwrite($file,$data);
  13. fclose($file);
  14. $file = fopen($path,"r");
  15. Header("Content-type: application/octet-stream");
  16. Header("Accept-Ranges: bytes");
  17. Header("Accept-Length: ".filesize($path));
  18. Header("Content-Disposition: attachment; filename=".basename($path));
  19. echo fread($file, filesize($path));
  20. fclose($file);
  21. unlink($path);
  22. $this->index();
  23. }
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn