A
A
Alexander Sidorov2010-10-06 17:52:29
PHP
Alexander Sidorov, 2010-10-06 17:52:29

Is it possible to determine in php whether a file is downloaded or not?

It is necessary to understand whether it is possible using php to determine whether a file has been downloaded or not, if so, how many times.
I don't remember or see any such possibility.
It can be done using AJAX + PHP,
but that's not it.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
T
TDz, 2010-10-08
@TDz

The only way to make sure that the client has received the entire file is to check if it has received all the data and check for errors. For a hardcore case, let's think that the client downloads the file in chunks in many streams and each chunk is considered a separate completed upload. Then the only way to make sure the file is served is to sum up the sizes and match the ranges. So, either you write a detailed log that includes these things, or you use post_action with the appropriate variables.
You can only check for errors by parsing the log. For the convenience of parsing, you need to customize the format and level of the log and parse it by comparing logged requests. Unfortunately, this still does not guarantee that the client received the file because the absence of HTTP errors does not guarantee correct saving on the screw.
If you need to hardcore make sure that the file fell on the client's screw safe and sound - make a downloader on flash, java, silverlight or other clientside technology that can check the result of the download. Do you really need it?

S
Stalker_RED, 2010-10-06
@Stalker_RED

if you really, really need it, you can give the file as a script. type
/getfile.php?id=12345
a on the server you will be sure that you sent it (but not the fact that the client accepted it) and this will slightly increase the load. another option is to give the user a link to a script that will increment the counter and then redirect to the file. but again, you won't be sure if the client actually accepted the file. in the case of pictures, they can be shown in the browser, and onload pictures send a message to the server. if desired, you can even check the integrity of the picture on the client. $filename = get_filename_by_id($_GET['id']);
readfile($filename);
// увеличиваем счетчик
// profit!

E
Eugene, 2010-10-06
@Nc_Soft

What files are given? I heard that in nginx there is some kind of action after the return of the file, who knows, please unsubscribe.

T
try4tune, 2010-10-06
@try4tune

Definitely no guarantee. Even if the server gave the entire file, the fact that the file was completely downloaded by the client is not a fact.

P
Pavel, 2010-10-06
@marabou

Of course, you can't, and PHP has nothing to do with it.

O
Oleg Matrozov, 2010-10-06
@Mear

Hmm... maybe try playing with partial-content some more? Those. Let's assume we have a script on the server that gives the file. In addition to the fact that it counts the beginning of the download, it artificially gives not the entire file, but only a part (without the last 10 bytes, for example). Those. when the browser requests the last 10 bytes in a separate request, this will be the fact that the download has completed. I really do not know how the browser will react to the Content-Range and Content-Length response headers without the Range header initiated from their side, but I think it's worth a try. Write, if possible, most interesting))

K
kenga, 2010-10-07
@kenga

And here you don't have too many options. I would do php + Nginx + x-accel-redirect + nginx log analysis.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question