Xyberviri

streaming files

Feb 9th, 2015
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. http://stackoverflow.com/questions/6914912/streaming-a-large-file-using-php
  2.  
  3. <?php
  4.  
  5. // the file you want to send
  6. $path = "path/to/file";
  7.  
  8. // the file name of the download, change this if needed
  9. $public_name = basename($path);
  10.  
  11. // get the file's mime type to send the correct content type header
  12. $finfo = finfo_open(FILEINFO_MIME_TYPE);
  13. $mime_type = finfo_file($finfo, $path);
  14.  
  15. // send the headers
  16. header("Content-Disposition: attachment; filename=$public_name;");
  17. header("Content-Type: $mime_type");
  18. header('Content-Length: ' . filesize($path));
  19.  
  20. // stream the file
  21. $fp = fopen($path, 'rb');
  22. fpassthru($fp);
  23. exit;
  24.  
  25. ?>
Add Comment
Please, Sign In to add comment