Sam Burdge – Smarter Than The Average Blog

Forcing a file to download using php headers

04.05.2009 (11:57 am) – Filed under: development, scripts

If you create a hyperlink to a media file that can be opened within the browser such as an mp3, mpg, jpg, pdf, etc. a single left click will open the file in the web browser instead of triggering a download. To download the file you need to right click (CTRL + click for mac) and choose 'Save File As...' from the dropdown.

If your intention is to create a link for the user to download the file rather than viewing it in their browser you can do so using a simple php script. Create a file called 'download.php' and copy in the following php:

<?php
$download_file = $_GET['file'];
$download_file_name = $_GET['name'];
$handle = fopen($download_file, "r");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$download_file_name);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($download_file));
ob_clean();
flush();
readfile($download_file);
fclose($handle);
exit;
?>

You can then create your download links like so:

www.example.com/download.php?file=images/example.jpg&name=hello.jpg

The URL should include the path to the file to be downloaded, and the name you want to give the file. In the above example the file is 'images/example.jpg' but the name of the file downloaded by the user would be 'hello.jpg'

When using PHP headers it is important to note that the headers will only be executed if they are called before any text is output to the page. Any html, or php echo tags, before the headers will cause the headers to be ignored. A line break or space before the opening php tag will also prevent headers from working.

Growing Userbase for my Simplistix Theme for WordPress

12.02.2009 (10:25 pm) – Filed under: blog, themes, wordpress

After releasing my WordPress theme Simplistix into the wild a few weeks ago I have been very happy, and somewhat surprised by it's popularity. It has received hundreds of downloads from my site and over 700 downloads from wordpress.org in the last 12 days. I knew that there was a niche for simple, text based blog themes as I had seen a few sites such as www.plaintxt.org that are entirely devoted to these type of themes. But, with all the sophisticated and complex wordpress themes on offer, Simplistix feels like quite a humble little theme — perhaps that's part of it's charm.

Anyway, seeing the download stats made me feel curious about who was using the theme. I had already seen it being used on a couple of blogs because, as with most wordpress projects, I had received some suggestions, ideas, support requests and constructive criticisms from members of the wordpress community. I did a bit of further research on google and instantly found loads more bloggers using my theme. The main thing that struck me was the diversity of subject matter that these blogs covered – science, computer programming, economics, movies, music, art, fashion and many more. It was also nice to see instances where people had modified the theme, adding in their own site headers, sidebar widgets, google advertising, etc.

I felt so inspired by seeing all these sites using Simplistix as their theme that I decided to write this post featuring some of my favourites. So here they are:

TOP PICKS

www.flyhypersonic.com – The seatbelt sign is illuminated
www.thewherewithal.org – Blogging about credit, debt, money, economy, theory
nicolasulloa.com/blog – Music, Animation, Graphic Arts and Illustration
www.ianthewebsite.com – If you could be any blog, what blog would you be?
2chicksblogging.com – Blogging for Change Training since 2008
feedingme.com
blog.nakedsteve.com – Oh hey is that a monome?

THE BEST OF THE REST

phoward.com/blog
ponasniekas.nespalvotas.lt
www.bigtechcenter.info
www.bletherskite.com
blog.xieer.com
www.bestmusiccenter.info
www.businesstechnologytimes.com/wordpress
likeitreallymatters.com
hasibul.info/blog

I am planning an update to the theme in the near future where I will add an options menu which will allow you to control colours, fonts etc.

76 digital remix - Home Page Template Preview

28.12.2008 (6:26 pm) – Filed under: blog, themes, wordpress

A quick update on my soon to be released 76 digital remix theme... Here is a sneak preview of one of the possible custom home page templates which will be fully configurable:  News  Feed  Home Page Template

Screenshots of some of the different layouts and color schemes, and of course the different flash site headers will be published here soon, so stay tuned for more sneak previews!