Forcing a file to download using php headers

Date: 4th May 2009 at 11:57 am | Filed under: development, scripts | Author: Sam Burdge | Tags: , , ,

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.

Leave a Comment

Flash Audio - Sound Visualisation & New Audio API

Date: 27th January 2009 at 11:37 pm | Filed under: development, flash | Author: Sam Burdge | Tags: , , ,

INSPIRATION

A long time ago I remember being inspired by the Dub Selector project at Infinite Wheel, a series of Flash movies that play heavy dub reggae loops, and incorporate various ways of triggering a selection of dub sound effects, drum rolls and keyboard notes. The project gave me the idea to create a more in-depth Flash music production tool, with many preset sounds and loops, and potentially audio sequencing tools too.

Dub SelectorDub SelectorDub Selector

MY PREVIOUS EXPERIMENTS WITH FLASH AND SOUND

This was back in the days of Flash 5 and I was a novice with Flash, I had only a basic grasp of actionscript. My first experiment was called ATG Beatbox. Here it is in all it's lo-fi glory!

Pretty basic,  but quite fun to play with too! The main problem I had was getting the samples to loop properly, and to get 2 or more samples to play in sync with each other. These restrictions made the possibility of sequencing very limited, so I ended up creating it so that the user could trigger the samples manually and had to time it right to get the 2 beats in sync.

The only way I could get the samples to loop cleanly was by importing them into the fla and attaching them to keyframes in the timeline.

I later made a few other experiments, such as a piano arpeggiator which used actionscript to play different arpeggio patterns. The timing was always an issue, and I concluded that Flash makes a lousy metronome! Unfortunately I seem to have lost the source files for this project :( so I can't provide an example.

Other more recent Flash projects I have done which include an element of sound are the SoundFX Player and Artanoid Game for 76 Creative. Artanoid uses the as2 attachSound method to load the mp3 files dynamically from the server.

SOUND VISUALISATION

New to actionscript 3 is the SoundMixer.computeSpectrum method, which takes a snapshot of the current sound wave and places it into the specified ByteArray object. The values are formatted as normalized floating-point values, in the range -1.0 to 1.0. The ByteArray object passed to the outputArray parameter is overwritten with the new values. The size of the ByteArray object created is fixed to 512 floating-point values, where the first 256 values represent the left audio channel, and the second 256 values represent the right audio channel.

It is explained in more depth in the article Sound Visualization in Flash CS3 by Tom Green, which is where I found out about it in the first place.

This is something I'm still experimenting with, but here's a basic example of what it can do:

Notice that because the audio sample is being loaded from the server using the Sound.load() method, the looping of the sample is still not satisfactory. The only way to make a sample loop properly still seems to be to import it and attach it to a keyframe. Here's another more abstract example:

There are a lot more cool examples of this type of Sound Visualisation at the AS3 Sound Spectrum Contest Results Be sure to check out the winning entry, which really demonstrates the scope of what can be done using computeSpectrum.

NEW SOUND API FOR FLASH 10

I recently discovered the Hobnox AudioTool, which is exactly the type of Flash based audio tool I imagined. It's actually amazing! As it features effects, like distortion, delay & reverb, phaser, etc. I could tell that, although the interface was flash, something else was being used to process the audio. The other thing I noticed was that the timing of it's drum machines was perfect! Something I've never been able to achieve with Flash.

Further investigation of the new sound API led me to these three articles by Adobe Engineer Tinic Uro, which seem to be a direct response to the Adobe, Make Some Noise campaign:

In Part 3 of the article he provides some code for a 'seamless loop' using the new extract() method with the samplesCallback event handler. I will put this code to the test as I am sure it will lead to new projects and experiments for me, the results of which will surely appear on my site in the near future!

Other Flash projects that utilise the new sound API are Tenoran, a sampling and basic sequencing instrument, and Noteflight, a a full-featured application that displays, edits, prints and plays back music notation.

Leave a Comment

Admin76 Web Content Management System

Date: 22nd January 2009 at 9:43 pm | Filed under: development | Author: Sam Burdge | Tags: , , ,

Admin76 is a powerful and versatile web content management system (CMS) designed and developed by 76 Creative. It is a PHP / mySQL driven project, for which I developed it's coding framework.

The main difference between Admin76 and other commercial CMS's is it's potential to be tailored exactly to the website it is powering. It can be transformed into a very 'bespoke' system, and so can be used to power many different genres of website, from a simple 5 page website, to a large news site, image or video gallery or a recruitment site. The only controls available in the CMS will be the exact controls you need to manage your site, nothing more, nothing less!

Other CMS's have certain 'tendencies' which relate to their intended user-base. For instance, WordPress is very much associated with blogging, Drupal is associated with community-driven sites. This is reflected in the possible themes, plugins and addons available for each.

Admin76 on the other hand is more flexible in this respect.  It can power a site with static pages, and news with categories and date based archives in the same way that WordPress can, but it can also power all sorts of different types of lists, with as many custom fields as you wish, e.g. address lists, list of file downloads, event diary, mp3 playlists, video playlists, etc. It can even be made to output XML, so it can be used to fully manage Flash Sites too.

As Admin76 is currently only available to customers of 76 Creative it has no 3rd party features, like plugins etc., available. This, however, is another strength of the system. All of Admin76's features are built in. It has an advanced image gallery system, with multiple file upload, medium size and thumbnail image creation.

Other standard features include RSS Feeds, Multiple Authors / Administrators, Flash Slideshow System, Flash Video Gallery System.

For more info about Admin76, and to enquire about getting your own self-managed, elegantly designed website get in touch with 76 Creative.

Some of the mySQL and PHP functions I have utilised in Admin76 will soon be available as tutorials on my site.

1 Response to “Admin76 Web Content Management System”

  • Comment by New e-commerce module for Admin76 CMS | Sam Burdge
    Date: June 26th, 2009 at 12:16 am

    [...] cart76, e-commerce I have been working for some months now to develop an e-commerce module for Admin76,  the CMS which is currently exclusive to 76 Creative. The e-commerce module, called Cart76, [...]

Leave a Comment

Leona Naess animated logo and holding page

Date: 15th August 2008 at 10:19 am | Filed under: flash, portfolio | Author: Sam Burdge

This holding page built for Polydor artist, singer / songwriter Leona Naess features an animated logo with random fades and glows. The flash random timing actionscript is something I have utilised in the past to create similar effects (see: ).

The holding page also features a streaming mp3 (using flash), mailing list signup form with javascript validation embedded youtube video and google analytics.

Check it out:

www.leonanaess.com

Leave a Comment

76 Digital Remix Theme

Date: 25th April 2008 at 5:02 pm | Filed under: blog, development, themes, wordpress | Author: Sam Burdge

I have updated my site with my new 76 digital remix theme for WordPress.

The new theme is built on a model I have created for a highly configurable, versatile set of premium themes which I will be releasing this summer. The premium themes will each come in three different versions – Editorial, Media and Ultimate (which combines the features of both editorial and media versions). The themes features will include:

Editorial Version

  • Dynamic site header
  • Rotating news on homepage
  • Feed aggregator to display news from other sites
  • Dropdown navigation for sub-pages
  • Sliding sidebar navigation
  • Sliding comments
  • Lightbox integration
  • Dynamic banner / google advertising integration
  • Gravatar support for authors and commenters
  • Widget ready
  • Plugin ready
  • Author profiles
  • Various post layout options
  • Multiple language support
  • Image gallery layouts
  • Easy to use setup page
  • Feed syndication
  • Various page layouts
  • Full Instructions

Media Version

  • Dynamic site header
  • Slideshow on homepage
  • Dropdown navigation for sub-pages
  • Sliding sidebar navigation
  • Sliding comments
  • Lightbox integration
  • Dynamic banner / google advertising integration
  • Gravatar support for authors and commenters
  • Widget ready
  • Plugin ready
  • Author profiles
  • Various post layout options
  • Multiple language support
  • Image gallery
  • Easy to use setup page
  • mp3 and video support
  • Feed syndication
  • Various page layouts
  • Full Instructions

I will also release a free 'light' version of the theme set, so watch this space!

3 Responses to “76 Digital Remix Theme”

  • Comment by Premium WP Theme News Links | WP-Premiums
    Date: April 25th, 2008 at 8:54 pm

    [...] Burdge is currently working on his 76 digital remix theme, which he is using on his blog at the moment and plans to release in the summer. The theme will be [...]

  • Comment by Леша
    Date: September 24th, 2008 at 3:46 pm

    Интересная штуковина, вот только стоит наверное тоже немало.

  • Comment by Daniel
    Date: February 26th, 2010 at 7:13 pm

    Hello is this theme (76 Digital Remix) Theme for sale ? I didn’t find the price here , I like it a lot thanks , Daniel

Leave a Comment