<p>I'm trying to find a way of finding out who is downloading what image from an image gallery. Users can download using a button beside the thumbnail or right click and use the "save link as" Is it possible to relate a user session or ID to a "save link as" action from all browsers using either PHP or JavaScript.</p>

[{'answer_id': 70633, 'author': 'Jesper Blad Jensen', 'author_id': 11559, 'author_profile': 'https://Stackoverflow.com/users/11559', 'pm_score': 0, 'selected': False, 'text': '<p>You need a gateway script, like ImageDownload.php?picture=me.jpg, or something like that.</p>\n\n<p>That page whould return the image bytes, as well as logging that the image is downloaded.</p>\n'}, {'answer_id': 70639, 'author': 'Henry B', 'author_id': 6414, 'author_profile': 'https://Stackoverflow.com/users/6414', 'pm_score': 0, 'selected': False, 'text': "<p>Because the images being saved are on their computer locally there would be no way to get that kind of information as they have already retrieved the image from your system. Even with javascript the best I know that you could do is to log each time a user presses the second mousebutton using some kind of ajax'y stuff.</p>\n\n<p>I don't really like the idea, but if you wanted to log everytime someone downloaded an image you could host the images inside a flash or java app that made it a requirement to click a download image button. That way the only way for them to get the image without doing that would be to either capture packets as they came into their side or take a screenshot.</p>\n"}, {'answer_id': 70664, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Yes, my preferred way of doing this would be via PHP. You\'d have to set up a script which would load up the file and send it to the user browser. This script would also be able to log the download somewhere (e.g. your database).</p>\n\n<p>For example - in very rough pseudo-code:</p>\n\n<p>download.php</p>\n\n<pre><code>$file = $_GET[\'file\'];\nupdateFileCount($file);\nheader(\'Content-Type: image/jpeg\');\nsendFile($file);\n</code></pre>\n\n<p>Then, you just have your download link point to download.php instead of the actual file. (Note that updateFileCount and sendFile are functions that you would have to provide, of course - <a href="http://elouai.com/force-download.php" rel="nofollow noreferrer">this script</a> is an example of a download script which you could use)</p>\n\n<p>Note: I highly recommend avoiding the use of $_GET[\'file\'] to get the whole filename - malicious users could use it to retrieve sensitive files from your web server. But the safe use of PHP downloads is a topic for another question.</p>\n'}, {'answer_id': 70669, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 0, 'selected': False, 'text': '<p>Your server access logs should already have the request for the non-thumbnailed version of the file, so you just need to modify the log format to include the sessionid, which I presume you can map back to a user.</p>\n'}, {'answer_id': 96582, 'author': 'Laith', 'author_id': 5961, 'author_profile': 'https://Stackoverflow.com/users/5961', 'pm_score': 0, 'selected': False, 'text': "<p>I agree strongly with the suggestion put forward by Phill Sacre. For what you are looking for this is the way to go. </p>\n\n<p>It also has the benefit of being potentially able to keep the tracked files out of the direct web path so that they can't be direct linked to.</p>\n\n<p>I use this method in a client site where the images are paid content so must be restricted access.</p>\n"}]
['https://Stackoverflow.com/questions/70600', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']