1

I have written code that creates a CSV file in PHP, and download it locally.

Is it possible to know whether the user has downloaded the file? Or if the user canceled downloading?

My test-code is placed below for creating and downloading the file:

header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=invoies.csv");
header("Pragma: no-cache");
header("Expires: 0");

$array = array(
    array("data11", "data12", "data13"),
    array("data21", "data22", "data23"),
    array("data31", "data32", "data23"),
);
outputCSV($exported_invoices_arr);


function outputCSV($data) {
    $outstream = fopen("php://output", "w");

    function __outputCSV(&$vals, $key, $filehandler) {
        fputcsv($filehandler, $vals); // add parameters if you want
    }

    array_walk($data, "__outputCSV", $outstream);
    fclose($outstream);
}

Is their any trigger, or handler while downloading the file?

8

2 Answers 2

0

Its not possible .There is no straight forward method to capture. There might be some work around but its not perfect.

2
  • 1
    That is not true (entirely). Mar 13, 2013 at 13:03
  • The same can be said for anything http/udp related.
    – Mike B
    Mar 13, 2013 at 13:58
0

You will never know. Even if you detect connection status, you're not sure, because a caching proxy could hide real user connection status. All what you know is if the script has sent all data, but not if file has been received.

You need to implement some client-side interactive downloader, like a java applet... but then you'll have other headaches.

Not the answer you're looking for? Browse other questions tagged or ask your own question.