Best way to implement a load counter?

Say the user clicks on the link to download the file. The user receives the save as a dialog box, but then clicks on cancel. How do you find this? If the user clicks on the cancel link or does not receive the entire file, the server should not record that the file was downloaded.

+3
source share
5 answers

In the past, I have done this:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
flush()
log()
exit;

the log should only be started after the file has finished reading, which means that the entire file has been transferred to the user. Some time has passed since I did this, and I don’t know where exactly the exact code is, so it may be inaccurate, but it should force you.

EDIT php.net, , , .

+3

, HTTPd , . -, , greps .

: nginx. . , Apache.

# 2: ? dupe-link SO. .

+2

, , -, , .

, , - , , , "" .

, , ( ack), , , , , .

,

  • - .
  • , - , , .

, , : (Pseudo Code).

1: Open File $foo; 
2: Loop while $foo is not EOF
     3: read  700kilobits from file $foo; 
     4: print 700kilobits of read data to web server
     5: execute webserver 'flush' which blocks until flush is complete. 
     6: <-- Loop
7: If all chunks of 700kilobits were read before user aborted transaction
     8: report file was downloaded. 

Unkwntech - , .
, , PHP, , , PHP, - , .
, .

+1

- ? , ? , , .

0

one way would be to write some PHP that handles the actual provision of the file supplied as the $ _REQUEST parameter. That the script will do the actual work of registering the download

0
source

All Articles