Shaun Mccran

My digital playground

11
M
A
Y
2011

Handling CFfile upload 'accept' file type errors

I was working on a system recently that allowed a user to upload images onto the server. It was restricted to files types of images, more specifically 'jpeg' and 'gif' files.

This is easily done with the 'accept' parameter, as documented in the ColdFusion documentation:

view plain print about
1Accept:
2
3Limits the MIME types to accept. Comma-delimited list. For example, the following code permits JPEG and Microsoft Word file uploads:
4accept = "image/jpg, application/msword"
5
6The browser uses the file extension to determine file type.

It is important to note here that it is the browser uses the file extension, so renaming an exe to jpg would fool it entirely.

Issues arise when you don't handle an invalid file upload in a friendly manner. In this case when a user tried to upload an incorrect file type they saw a nasty unformatted error message stating that the request could not be processed as the file was the wrong Mime type.

You cannot tell what the file type is until you attempt to upload it, so wrap your cffile tags in a simple try-catch and handle any errors in the same fashion as you normally would, I.E. by handling the system message and instead displaying a nice, user friendly message that doesn't sound like it was written by robots.

view plain print about
1<cftry>
2
3<cffile action="upload" destination="#request.uploadPath#" fileField="form.new_image" accept="image/jpeg, image/gif" nameConflict="overwrite">
4
5<cfcatch>
6
7    <cfset attributes.errors.type = 'error'>
8    <cfset attributes.errors.message = "The type of file you have tried to upload is not allowed, please select a jpg or gif.">
9    <cfset request.continue = false>
10
11</cfcatch>
12
13</cftry>

31
M
A
R
2011

Plesk 10.1.1 release adds ColdFusion 9 support

It seems as though the newest version of the server management software 'Plesk' v 10.1.1 is now officially ColdFusion 9 compatible.

Previously Plesk could only integrate with ColdFusion 8 as it caused instability issues with ColdFusion 9.

There isn't much about this in the release notes, just a simple statement.

view plain print about
1ColdFusion 9 support. A new version of the popular site developing tool is available.

The full release notes article is here: http://download1.parallels.com/Plesk/PP10/10.1.1/release-notes/parallels-plesk-panel-10.1.1-for-windows-based-os.html

I'm hoping it works well as I've just commissioned a new server running both these software versions.

28
M
A
R
2011

Getting Video thumbnails from YouTube

I want to display an image thumbnail on a page, so that a user can click on it and the video will pop up in a lightbox. But how do I get a thumbnail image of the video I want? This article shows you how you can quickly and easily use a Youtube URL to get video thumbnails.

There is a demo of this here: http://www.mccran.co.uk/examples/youtube-thumbs/

[ More ]

18
F
E
B
2011

Daily Dilbert RIAforge project release 1.0

I'm a great fan of the Dilbert cartoon series, so I've put together a little application to go and get the Daily Dilbert cartoon strip from the Dilbert website.

It's a simply cfc call that will get today's Dilbert cartoon and save it to a path the user has defined and passed in as an argument.

Let me know if you use it, or think of any ways of to extend it.

It is also one of the first tests I was set as a trainee 10+ years ago, so was quite an interesting comparison to write it again.

You can download it from RIAforge here: http://dilbert.riaforge.org/

_UNKNOWNTRANSLATION_ /