Best way to transparently download logs?

I have a personal project that has been online for some time. I do download counting by doing this:

  • When the user clicks the download link, he turns to a PHP script that writes some information to the table.
  • After writing the data, the script returns the path to the actual file.
  • Then the user has the ability to save the file to his hard drive, as if it were any other download.

This worked quite well for a while; however, it does not allow users to have the right-click > save target as... option because they actually see download.php in the Save File dialog box. Thus, the only way to download the project is to left-click on the link.

I would like to improve the process so that the user can download the project using any method by which he / she is most convenient. So, what are some more efficient ways to transparently download logs without user intervention?

For what it's worth , the machine is a standard LAMP stack, so there are no .NET parameters here.

+3
download lamp
Jan 30 '09 at 0:01
source share
4 answers

This is taken from php-documentation , but it is also possible to use different script languages:

 <?php // We'll be outputting a PDF header('Content-type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="downloaded.pdf"'); // The PDF source is in original.pdf readfile('original.pdf'); ?> 

The content of the Content-Disposition HTTP header tells it to save it as a download.

Another option is to regularly check your log files, for example, every day, using a script.

+3
Jan 30 '09 at 0:18
source share

For this reason, many sites use a download link that will lead you to another page that will automatically download the download when the page loads, and also give the user a link for direct download. This is basically a way to get pageviews for ad impressions, but also helps keep track of who uploads their files more easily.

+1
Jan 30 '09 at 0:08
source share

This answer details how to use the upload page to register a download, and also start downloading a file as soon as someone clicks on the link. I recently checked it for a right click.

I am using php middle-man to upload files to a file. The formatted URL http://192.168.1.1/xfer.php?file=Li9zb25ncy9HTE9XX0xlYXZlIFlvdXIgSGF0IE9uLm1wMw results in a file name for both Save As ... and left-click in Firefox.

Here is my xfer.php

 <? $filename = base64_url_decode($_GET['file']); if ($_GET['file']){ header("Cache-Control: public"); header("Content-Description: File Transfer"); header('Content-disposition: attachment; filename='.str_replace(" ", "_",basename($filename))); header("Content-Transfer-Encoding: binary"); header('Content-Length: '. filesize($filename)); readfile($filename); } $fh = fopen("test.html","a"); fwrite($fh,basename($filename)."\n<br />"); fclose($fh); function base64_url_decode($input) { return base64_decode(strtr($input, '-_,', '+/=')); } ?> 

And the page that links to xfer.php,

 $link = "xfer.php?file=".base64_url_encode("./songs/$key"); 

with $key being the file name, and songs is the folder where the file names are stored.

+1
Jan 30 '09 at 0:11
source share

Setting up Google Analytics? :)

+1
Jan 30 '09 at 1:40
source share



All Articles