Handling download abort in PHP

Posted by Aron Rotteveel on Stack Overflow See other posts from Stack Overflow or by Aron Rotteveel
Published on 2010-05-12T15:31:09Z Indexed on 2010/05/12 15:34 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

Is it somehow possible to handle a download abort in PHP?

In this specific case I am not speaking of a connection abort, but handling the event that triggers when the 'cancel' button in the browser download dialog button is clicked.

Since this dialog already interprets the headers of the file that is to be download but does not actually start the download, it only seems logical there should be some way to catch this.

Small (pseudo) code example to clear things up:

// set some headers
header('...');

// Question: what happens between the part where the headers are sent
// and the actual data is being outputted to the client? IE: this is the part
// where the download dialog should show up
// Logical question that follows is: is there a way to detect a 'cancel'?

$filename = '/some/file.txt';
$handle = fopen($filename, 'rb');
// output data to client
while (!feof($handle))
{
    echo fread($handle, 8096);
}
fclose($handle);

© Stack Overflow or respective owner

Related posts about php

Related posts about download