Monday 6 September 2010

Uploading pdf's with CodeIgniter

Small tip for anyone tearing their few remaining strands of greying hair out while trying to persuade CodeIgniter (currently version 1.7.2) to upload pdf files.

The problem seems to be that the Mime definitions in application/config/mimes.php are hideously limited for "pdf".

Look for the line

‘pdf’   =>      array(‘application/pdf’, ‘application/x-pdf’)


I changed this to

array('application/pdf', 'application/x-pdf', 'application/x-download','application/x-download', 'binary/octet-stream', 'application/unknown', 'application/force-download', 'application/octetstream')

I'm sure there's a million other variations on a theme but this at least got me started with open office 3 (mac version) pdf exports.

Sunday 8 August 2010

jQuery attribute equals selector using namespaces

First blog post in absolutely ages but thought I might just share this little bit of wisdom with the world. I've been rocking the jQuery endlessly recently on a big project and hit upon an annoying little snag over the last day or two.

jQuery selectors are brilliant, totally amazing, usually... now I've been getting well into using a local namespace for this site so I can throw endless data around in HTML attributes instead of being naughty and hiding data in rel attributes. This way I can put as much as I like in a tag i.e.

<span id="data" gl:cat_id="5">

or whatever then drag it out using some jQuery that looks like

$('#data').attr('gl:cat_id');

Great, easy, no problem. What I tried next was selecting by the custom attribute:

$('span[gl:cat_id="5"]')

Nope, no luck there... here's the pearl of wisdom: bung an escape in and happy days:

$('span[gl\\:cat_id="5"]')

and you're back on the road.