Guest User

Untitled

a guest
Sep 25th, 2012
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function sendTest() {
  2. $res = sendFile('POW.rar', 'herpderp.rar');
  3. }
  4.  
  5. function sendFile($path, $filename) {
  6.  
  7. ignore_user_abort(true);
  8. ob_start();
  9. header("Cache-Control: public, must-revalidate");
  10. header("Pragma: no-cache");
  11. header("Content-Type: application/octet-stream");
  12. header('Content-Transfer-Encoding: binary');
  13. //header("Content-Length: " .(string)(filesize($path)) );
  14. header('Content-Disposition: attachment; filename="'.$filename.'"');
  15. header("Content-Transfer-Encoding: binary\n");
  16. ob_end_clean();
  17.  
  18. $res = array(
  19. 'status' => false,
  20. 'errors' => array(),
  21. 'readfileStatus' => null,
  22. 'aborted' => false
  23. );
  24.  
  25. $res['readfileStatus'] = readfile($path);
  26.  
  27. if ($res['readfileStatus'] === false) {
  28. $res['errors'][] = 'readfile failed.';
  29. $res['status'] = false;
  30. }
  31.  
  32. if (connection_aborted()) {
  33. $res['errors'][] = 'Connection aborted.';
  34. $res['aborted'] = true;
  35. $res['status'] = false;
  36. }
  37.  
  38. return $res;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment