ricbax Posted November 8, 2006 Share Posted November 8, 2006 Here is the situation:I want to capture when a file gets downloaded, basically a counter that sends the value to my db.The problem: Due to plugins and browser issues I have disabled the the ability to download with a left-click (which rules out $_GET), forcing a right-click and the user choosing the Save Link As option from the pop-up menu.So my question is how can I capture the right-click and progress a counter?TIAricbax Link to comment https://forums.phpfreaks.com/topic/26597-php-capture-download-from-right-click-save-link-as-solved/ Share on other sites More sharing options...
bqallover Posted November 8, 2006 Share Posted November 8, 2006 The only thing I can think of is to have your link point to a wrapper PHP file that updates your database, then sends a redirect header to the file you want to download. Not sure if that works though. :)BTW, just checked and it seems you can't attach a javascript event to the 'Save link as...' context menu item, only to the firing of the context menu itself. Link to comment https://forums.phpfreaks.com/topic/26597-php-capture-download-from-right-click-save-link-as-solved/#findComment-121665 Share on other sites More sharing options...
ricbax Posted November 8, 2006 Author Share Posted November 8, 2006 Any suggestions on the wrapper ??? Link to comment https://forums.phpfreaks.com/topic/26597-php-capture-download-from-right-click-save-link-as-solved/#findComment-121803 Share on other sites More sharing options...
bqallover Posted November 8, 2006 Share Posted November 8, 2006 Erm. . . Something along the lines of this?[code]<?php/* * ... Increase your DB counter here ... */// required for IE, otherwise Content-disposition is ignoredif(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // We'll be outputting a PDFheader('Content-type: application/pdf');// It will be called downloaded.pdfheader('Content-Disposition: attachment; filename="downloaded.pdf"');// The PDF source is in original.pdfreadfile('original.pdf');?>[/code]I've lifted most of that from the [url=http://uk2.php.net/header]header[/url] manual page at PHP.net, and the IE bug workaround from somewhere else. Not sure if that fix works though. For much more on this sort of thing, do a 'Find on this page...' for 'Content-Disposition' on the above linked php.net header page.good luck with it :)EDIT: Of course, the above is just an example, you'd have to change MIME type for your specific file. Link to comment https://forums.phpfreaks.com/topic/26597-php-capture-download-from-right-click-save-link-as-solved/#findComment-121808 Share on other sites More sharing options...
ricbax Posted November 10, 2006 Author Share Posted November 10, 2006 Sometimes it is right in front of your eyes ... :oThanks ... works a treat! Link to comment https://forums.phpfreaks.com/topic/26597-php-capture-download-from-right-click-save-link-as-solved/#findComment-122727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.