Filed under:
Code
CakePHP

Important! This is old code. I’ve not used it for a long time. It might still be useful. Be careful.

 

This snippet is a CakePHP component which can be used to force a users browser to download a specified file instead of attempting to display it. It will happily deal with any file your scripts have read access to. When provided with an absolute file location and filename for the downloaded file, it will attempt to look up an appropriate mime-type for the file, output some HTTP headers followed by the file data itself.

You are responsible for exiting after calling this method. Not exiting will result in CakePHP trying to render a page after sending the file data, causing (possibly invisible) errors. I have also removed error checking code responsible for checking the file path and download name as it is very app-specific. You will probably want to add your own.

Note: I have not tested this on a Windows-based machine. I don’t see why it shouldn’t work, but you have been told.

 

Usage

var $components = array(‘ForceDownload’) … $this->ForceDownload->forceDownload(’/path/to/file.php’, ‘MyPHPFile.php’); exit();

 

Download force_download.zip

Filed under:
Code
CakePHP

Important! This is old code. I’ve not used it for a long time. It might still be useful. Be careful.

 

Favatars is a Wordpress plugin for displaying favicons as avatars next to blog post comments. This code is an adaptation of the original work to turn it into a CakePHP Controller. When given a URL, it will attempt to locate a favicon for that site. If one is found, it is cached and displayed. If not, it will display a default image.

By using this controller within<img> tags, favicons can be used as images anywhere within your site, without knowing their specific address. It is currently in use on this blog and favicons will appear next to post comments.

Instructions for use are included in the download. I can no longer offer support for this code.

Favatars.zip