|
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:
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.
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>
|
Things I saw at the Gadget show live - Long live the QR Code |
||||||||
I was recently at the Gadget show live exhibition event at the National Exhibition center in Birmingham. One of the first things I noticed was the proliferation of the QR, Quick Response, code.
It is exactly the right sort of environment for it, being a Gadget and Technology based event, and there are undoubtedly a higher percentage of smart phone users in the crowd, but it was great to see a lot of exhibitors using QR codes on their stands.
|
Things I saw at the Gadget show live - Gaming Exhibition area |
||||||||
Nintendo had a great display of all of their handheld console throughout the ages, right up to the 3DS, which takes a little getting used to.
|
Things I saw at the Gadget show live - Cat Genie self flushing cat box |
||||||||
The Gadget Show live Birmingham exhibition happened a few weeks ago, and amongst the exhibition stands there I spotted a rather intriguing cat gadget.
I've got a family of cats so I'm always interest in cat related gadgetry but I think perhaps an automated litter box might be a bit too much.
That's right, the image above is from this site, http://www.catgenie.co.uk/ where you can watch a video of the self flushing cat litter toilet. This thing is huge, and about as loud as our Dyson vacuum cleaner. I'm dubious as to whether any of my cats would even get near it let alone in it.








