Main Content

Downloading a report from the web for further local analysis

Archive - Originally posted on "The Horse's Mouth" - 2010-08-13 08:10:28 - Graham Ellis

There are many applications where users want to use a piece of web based software to explore data sets - to research information and come up with tables of results and lists of data which they then want to examine in more detail - explore further.

How do they do that further exploration - perhaps through another piece of software such as Microsoft Excel, or another spread sheet, rather than via a web application.

If you want to send out information to a browser that it's to save to disc, you can change the header from
  Content-type: text/html
to
  Content-type: application/octet-stream
and the browser will ask you how / where you wish to save the data; it's always done this way through the browser so that users aren't at risk of having servers quietly hide files on their systems without their knowledge.

Using a language such as PHP, you can not only change the content type header but also:
• reformat the data from HTML to something else
• set the name under which the file should be stored locally

There's an example (from the PHP course concluded yesterday) [source] and [run it] on our site. The initial web based report that the page gives you an analysis of the most visited 1000 pages on our web site, ranked by popularity using a decaying moving average. That's a great report, but I might like to pull it into Excel, so the "download a copy" button close to the top of the page presents that same data, as an application/octet-stream, in a tab separated field format that's easy to import into the Microsoft (or other people's) spread sheet.