Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sendTest() {
- $res = sendFile('POW.rar', 'herpderp.rar');
- }
- function sendFile($path, $filename) {
- ignore_user_abort(true);
- ob_start();
- header("Cache-Control: public, must-revalidate");
- header("Pragma: no-cache");
- header("Content-Type: application/octet-stream");
- header('Content-Transfer-Encoding: binary');
- //header("Content-Length: " .(string)(filesize($path)) );
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- header("Content-Transfer-Encoding: binary\n");
- ob_end_clean();
- $res = array(
- 'status' => false,
- 'errors' => array(),
- 'readfileStatus' => null,
- 'aborted' => false
- );
- $res['readfileStatus'] = readfile($path);
- if ($res['readfileStatus'] === false) {
- $res['errors'][] = 'readfile failed.';
- $res['status'] = false;
- }
- if (connection_aborted()) {
- $res['errors'][] = 'Connection aborted.';
- $res['aborted'] = true;
- $res['status'] = false;
- }
- return $res;
- }
Advertisement
Add Comment
Please, Sign In to add comment