Is there any way to set a event or run a function because of 'User downloading a File'?

Comments

A suggestion

Hello,
Yes.

One way would be to write a custom module. You could create a custom path (implement hook_menu). Your hook menu implementation would call your custom logic when a user requests your custom url/path.

You can also peruse the API and other docs provided on this site :)

Good Luck:)

Thinking is the best way to travel.

Probably there is, but you'll

Probably there is, but you'll need to provide a bit more background about how the file is being served to the user. In the most common case of public access to files the URL of the file is mapped directly to its location on disk and the web server just serves it to the user with no Drupal code being executed. If you have private access configured then you can implement hook_file_download to detect all download events. But private access may be undesirable for performance reasons.

It's possible to implement a home grown variant of private access for a subset of files. There may well be modules that help with this. The general approach would be to do something like extending the filefield widget so the download URL it generates points to an internal path the callback of which fires your extra processing before executing a passthru to the original file.

Thanks I will try the

Thanks I will try the Callback version

Until the server crashes you're doing it quite right