Php can detect whether a user has started downloading a project to download files, because it needs to check whether the user has completed downloading. there is a piece of code below... ignore_user_abort (true); if & nbsp; ($ fd & nbsp; = & nbsp; fopen ($ filePath, & nbsp; 'RB ')) & php: Check whether the user has started downloading
There is a project that provides file download, because you need to check whether the user has completed the download, there is a piece of code below
...
ignore_user_abort(true);
if ($fd = fopen($filePath, 'rb')) {
session_write_close();
if ($start_offset > 0)
fseek($fd, $start_offset);
while (!feof($fd)) {
print (fread($fd, 16384));
}
fclose($fd);
}
if (connection_aborted()){
...
}
else {
...
}
...
Now, a problem occurs: if it is a large file, there is nothing to do. if it is a small file, when the user sees the select storage directory dialog box, wait a moment and then click cancel, the server has sent all files, so if (connection_aborted () is false.
I want to ask if there is any way. for example, if a user finds that the first print has not started downloading, print is paused, or is there a way to disable a print such as buffering so that the print block is not accepted by the user, that is, the print cannot be returned?
Unclear explanation
------ Solution --------------------
PHP cannot know.
------ Solution --------------------
PHP server script, that is the behavior of the browser, php is powerless.
------ Solution --------------------
Put if (connection_aborted () {... in a loop
------ Solution --------------------
The server sends the header followed by the file data
After the browser receives the header, it immediately receives subsequent data. While parsing the header in the browser, the download has started, but it is downloaded to the cache.
------ Solution --------------------
Reference:
Python.
The underlying protocol has nothing to do with the language. if both parties agree, php can also