Archive for the ‘ColdFusion’ Category

How to resize and crop Image Using Coldfusion script

April 7, 2013 Leave a comment

I had requirement on my site  to resize Image after uploaded by user in two sizes one for view page and one as thumbnail, I found some script on web and improved it to fit in my requirement. here it is. I expect this code will reside in a CFC function


var l = {}; // local struct

/* Read file  and we will resize and crop it to make 200×200 */

l.img = ImageRead(“path of the image to be resized”);

l.resizeOriginalFlag = 0;
If( l.img.height GT l.img.width )
If( l.img.height GT 200)
ImageResize( l.img,’200′,”);
l.resizeOriginalFlag = 1;
l.fromX = l.img.Height / 2 – 100;
else if( l.img.width GT l.img.height )
If( l.img.width GT 200 )
ImageResize( l.img, ”,’200′);
l.resizeOriginalFlag = 1;
l.fromY = l.img.Width / 2 – 100;
ImageCrop( l.img,l.fromY,0,200,200);
If( l.img.height GT 200)
l.resizeOriginalFlag = 1;


<cfif l.resizeOriginalFlag>
<cfimage action=”write”
destination=”<path with filename>”
<!— <cfdump output=”/sites/resize.html” var=”#cfcatch#” format=”html”> —>

How to configure Railo – Tomcat – Apache on MAC Lion Mountain 10.8

January 22, 2013 5 comments

Last week I updated my operating system from Snow Leopard  to Lion Mountain 10.8, system has upgraded itself.

Only two problems I faced:

1) Little Snitch got removed (V 2.2), I had to buy Licence for upgrade of version 3.02 – Lion cost me more 😦

2) I had ColdFusion 9.01, which stopped working as Lion upgrade had reinstalled Apache removed old httpd.conf and httpd-vhost.conf files (actually renamed them as httpd.conf~previous.

I tried to move virtual sites from old to new but it didn’t work.

Web Sharing option got removed from System Preference – To get it back I found this post which provides a tool to get it in Sys Pref under Other:

Explanation, good article to read: Restore Web Sharing in Mountain Lion 

Get the tool from here: WEB SHARING IN OS X MOUNTAIN LION

I made few changes to Apache config files, by default it uses web server document folder here:


I have changed this and few other settings in httpd.conf (/private/etc/apache2/)

1) Find ServerAdmin and change email address to yours one (around line no 153)

2) Find ServerName and change it to cfdev also add following in hosts file (/private/etc/) cfdev  (now you can get to your webserver by localhoost/ cfdev/

Make sure you uncomment this line (at line no 481) Include /private/etc/apache2/extra/httpd-vhosts.conf

3) create a folder sites or whatever name you waant to give at root level

4) Find DocumentRoot (line no 169) and change it to “/sites”

5) Find < Directory and change it with “/sites”

6) Open file httpd-vhost.conf from /private/etc/apache2/extra/

7) Uncomment NameVirtualHost *:80 (Line no 19)

8) Add following virtual host (default) site

<VirtualHost *:80>
DocumentRoot “/sites”
ServerName cfdev
DirectoryIndex index.html


9) Add / Create index.html in /sites folder as a place holder

10) sudo apachectl restart (to pick-up the changes

now open browser and browse http://cfdev or http://localhost and you should see your default web page

Railo Installation:

Download your railo installer from here

Scroll down and pick MacOS installer infront of Railo Server with Tomcat 7 title

Open it up and follow the default steps:

It will normally Install under this location and picks port 8080 – /Library/Railo/tomcat/

now if you browse http://localhost:8080/ you should see the tomcat page

1) Open web.xml from tomcat/conf folder

Add following at around line 422 (This will help if you use CFWheels frame-work


2) Open server.xml from tomcat/conf

3) go to line no 90 and un comment following:

<Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />

This will help us to use apache server on port 80 to create virtual sites.

at around line 123 you will see default website for this Tomcat server

create a folder under /sites folder – which will be your first local site say – firstSite

inside the folder create index.cfm

now create a virtual site in server.xml like this: (above </Engine>)

<Host name=”” appBase=”webapps”
unpackWARs=”true” autoDeploy=”true”
xmlValidation=”false” xmlNamespaceAware=”false”>
<Context path=”” docBase=”/sites/firstSite”/>

save the file and restart the server (Tomcat):

4) open terminal window and go to /Library/Railo/tomcat/bin

run following command: sudo sh (to shutdown the server)

Now run this command to start it: sudo sh

5) add following in hosts file:

now browse and you will see your first site index.cfm running

6) open httpd.conf from /private/etc/apache2/

add following (Thanks to Anuj Gakhar this post)

<Proxy *>
Allow from

ProxyPreserveHost On
ProxyPassMatch ^/flex2gateway/(.*)$ ajp://localhost:8009/flex2gateway/$
ProxyPassMatch ^/messagebroker/(.*)$ ajp://localhost:8009/messagebroker/$1
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8009/$1$2

now open httpd-vhosts.conf from /apache2/extra/ folder and add virtual site (key to this set up is you need to add virtual site pointing to the same folder with same url under both servers)

DocumentRoot /sites/firstSite
DirectoryIndex index.cfm
<Directory “/sites/firstSite”>
AllowOverride All
Order allow,deny
Allow from all
Options +Indexes
ErrorLog firstsite.error.log
LogLevel warn

restart your apache server and

browse  and you should see your site running on port 80


ColdFusion – Cross Site Scripting

March 8, 2011 1 comment

I had to fix one site which was sharing server with other sites to be PCI compliant for Cross Site Scripting and DB Injections.

Here are the few things I did to accomplish this.

In Application.cfc, I have added following:

<cfset this.scriptProtect = “all” >

Note: If you are passing object/script or any html  etc tags in form or query variable, this will break your code

Make sure you have following section in your cfusion/lib/neo-security.xml:

<var name=”CrossSiteScriptPatterns”>
<struct type=”coldfusion.server.ConfigMap”><!– this one is for site scripting –>
<var name=”&lt;\s*(object|embed|script|applet|meta|iframe|style|img|form|xss|body|html|head|title|input|layer|br|bgsound|link|xml|frameset|table|div|hr|base|a%20href|a href)”>
</var><!– following is for SQL injections –>
<var name=”;.*(select|insert|update|delete|drop|alter|create)”>

Now all you need to do is find the respective string in your out-put and display the (send user to) appropriate error/ message page

Categories: ColdFusion, Secure

Extending CFC – DAO

August 17, 2010 2 comments

I came across very strange behaviour of extending CFC to another CFC for my DTO’s, which I was using to send data back to my Flex application using AMF.

My Main parent CFC had 3 properties.
I created new CFC and extended to the above CFC and added 3 more properties.
It works fine with in ColdFusion, but when I used it to return to my Flex application with type binding to my ActionScript DTO.
This wasn’t sending the parents properties to my Flex application.
To fix this I had to add all properties in my extended CFC (Child one).

Has any one come across the similar scenario?

How to Improve Flex data transfer from CF?

August 15, 2010 Leave a comment

I found this article and realised that transferring data from CF (CFC objects) to Flex application using this way will reduce the packet size and improve the performance.

You don’t need to create an object of the CFC type you want to send data across in your array, but what you need to do is take following steps and you can improve your application’s performance:

Following code is how I used to send data across to my Flex App:

<cfloop query=”myQuery”>


local.result = createObject(“component”,”com.philip.myproj.myobj”);



arrayAppend(local.results, local.result);



The above method is how most of the developers use and it works fine only downside is this passes the complete object with all setter’s and getter’s and makes it bulky.

The following method is very light weight to pass the objects around and its documented in here: Writing the ColdFusion CFCs

you just need to change the object creation step with creating a simple Struct and you need to add an extra line to declare its a type of following CFC Value object likt this:

local.result[“__type__”] =”com.philip.myproj.myobj”;

Here is how you write the code using above type declaration:

<cfloop query=”myQuery”>


local.result = structNew();

local.result[“__type__”] = “com.philip.myproj.myobj”;

local.result[“prop1”] = myQuery.val1;

local.result[“prop2”] = myQuery.val2;

arrayAppend(local.results, local.result);



And Flax / Flash is sharp enough to pick this up and automatically link with ActionsScript VO class and you will get typed data.

Categories: Adobe, ColdFusion, Flex

Few frequently used Regular Expressions by me.

August 13, 2010 Leave a comment

In ColdFusion:
1) To match a valid UK postcode and returns an array with one item of valid postcode otherwise returns array with no item in it:
Pattern to test (with or without spaces):

^ : is for start of the string

$: is for end of the string

?: zero or one letter (optional)

{1,2}: minimum 1 or maximum 2 characters

Pattern Example
A9 9AA M1 1BA
A99 9AA N12 1UD
AA99 9AA RG6 1WG
Special case for National Girobank

<cfset arr = REMatch(“^[A-Za-z]{1,2}[0-9R][0-9A-Za-z]?[[:space:]]?[0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z][A-Za-z]$”,request.postcode)>
<cfif len(arr) GT 1>
<cfreturn true >
<cfreturn true >

2) Another one for UK post code, little bit complicated

<cfset arr = REMatch(“^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$”,request.postcode)>

Few references for UK Postcode regex)

Ref Site Link 1, Ref Site Link 2

3) To validate number with minimum 11 char and maximum 14 car using isValid function


4) To remove all characters from the string except alpha numeric:

REReplace(stringvar, “[^a-zA-Z0-9]”,””,”All”);

In JavaScript:

To restrict any thing except alpha numeric (case insensitive)

string.replace(/[^a-zA-Z0-9]/g, “”)

To Replace brackets, dots and spaces from string globally

string.replace(/[\(\)\.\-\ ]/g, ”)

In ActionScript:

1) Phone number check through regEx validator:

private const UK_PHONE_NO_REGEX:String = ‘^[0+][0-9]{10,14}$’;

number can start with 0 or plus (+) , with minimum 10 and maximum 14 characters

2) removes double quotes from string:

var pattern1:RegExp = new RegExp(‘”‘, “g”);


JavaScript Regular expression replacement:

Add comma separator to numbers like 10,000.00

variable.toString().split(“”).reverse().join(“”).replace(/(\d\d\d)(?=.)/g, “$1,”).split(“”).reverse().join(“”);
if you want to separate by (.) dot than replace comma with dot in here “$1,” in above string.

Complax Array Sorting in ColdFusion

August 4, 2010 Leave a comment

I needed to sort my cold fusion array which had complex Structure as CFC DTO in the array item.

I found very useful blog of Martin

Its very easy to implement. Actually I changed a little bit, I saved the UDF in a CFC and extended my main CFC to this new CFC and it worked straight away.

Here is the code how to call it.

arrayToSort = ,
sortKeys = [{'keyName':'yourKeyToSortOn'},{'sortOrder':'Ascending OR Descending'}],
doDuplicate = false,
useGetterMethods = false);

To download the code

Happy Coding

Categories: ColdFusion Tags:

Coldfusion transaction error

June 1, 2010 Leave a comment

I came across very weird error from one of my cold fusion cfc page, which has quite a lengthy cftransaction in it with quite a lot insert queries and the error was:
Branch target offset too large for short

I had to split the code in 2 pages and moved transactions in and include page though I am against having an include page in cfc but for time being wanted this code to work, found an article related to this problem here:
Branch offset error

I am very amazed that this error is in Cold fusion from CF7 and CF9 still throws the same error.

I will try to ask the solutions from ColdFusion Gurus.

Categories: ColdFusion, transaction

Coldfusion 8 Query feature

May 29, 2010 Leave a comment

This post is the extension of my earlier post – 10 March 2009

Actually I wrote about getting Identity column value, when inserting a new record in MSSQL data base. but few days ago I found out from Ben Forta’s blog, here is the link to that blog and content:

If you are using a database table with an identity (auto-increment) field, ColdFusion 8 can automatically return the newly created field value for you, without needing a trigger or a subsequent . All you need to do is look in the optional RESULT structure, and if available the value will just be there. This feature is very DBMS and driver specific (and unfortunately does not seem to be supported by Apache Derby), and the name of the structure member containing the generated value is different based on the DBMS being used. Here are the ones you should be aware of:

* SQL Server: result.IDENTITYCOL
* Oracle: result.ROWID
* Sybase: result.SYB_IDENTITY
* Informix: result.SERIAL_COL
* DB2: result.KEY_VALUE
* MySQL: result.GENERATED_KEY (MySQL 4 and 5 only, MySQL 3 does not support this feature)

Ben Forta’s Article link

Categories: ColdFusion, MSSQL, MySQL

Adobe ColdFusion 9 in parallel with Macromedia ColdFusion 6 (or 7,8)

January 22, 2010 Leave a comment

I managed to install Adobe ColdFusion 9 on my machine when I was contracting in Exeter. First I managed to convince them to move forward to use CF9 and helped them by installing CF9 in parallel to Macromedia ColdFusion 6 on their DEV machines so they can test their existing code and compare between both versions, I also used CF9’s excellent feature “Code Analyser” to analyse the existing code, and it was a great help:
Here are the steps I took to Install CF9 and get it working:
(I achieved this by going through few blogs: I can’t remember the url’s, but update here)

CF9 Installation Guide
These are the steps you need to take to install CF9 in parallel to CF6 and uses Apache web server:
1) Download CF9 Trial version from
2) Stop CF 6 Admin service (Macromedia JRun Admin Server ) (if running), and also turn Start-up Type to Manual
3) Stop CF6 Cfusion service (Macromedia JRun CFusion Server)
4) Stop CF6 Default service (Macromedia JRun Default Server) (if running), and also turn Start-up type to Manual
5) If any other CF 6 services are running, like ODBC, Search/ Verity – turn them off
6) Find the CF 9 installer and run it by double clicking it
7) Opt for the trial version
8) (IMP) Change the Folder (Default option of Jrun4) to CF9Jrun4 as Jrun4 is being used by CF 6
9) Opt for installation type Multi-Server (2nd Option), (That’s what we want in here)
10) And Opt for in-built Application web server (You don’t want to play with existing Apache web server config file)
11) You don’t need Any of ODBC, .Net services except documentation (But you can make your own call here), I would say don’t select them for this test environment.
12) Let it install and finish, if you get any message of failure, look at the log, normally you get warning about some folders can’t be removed, you can ignore this.
13) Open jrun.xml from C:\CF9Jrun4\servers\admin\SERVER-INF
a. Find “jrun.servlet.http.WebService” service and change port to 8001 (or any no, which is not being used by CF6)
b. Find “jrun.servlet.jrpp.JRunProxyService” service and change port to 51002 (or any no, which is not being used by CF6)
14) Open jrun.xml from C:\CF9Jrun4\servers\cfusion\SERVER-INF
a. Find “jrun.servlet.http.WebService” service and change port to 8383 (or any no, which is not being used by CF6)
b. Find “jrun.servlet.jrpp.JRunProxyService” service and change port to 51000 (or any no, which is not being used by CF6)
15) Save both files and re-start your machine
16) Open “Jrun Launcher” from Start/All Programs/Adobe/Coldfusion 9 (multi server version)/
a. Start Admin server
b. Start Cfusion server
17) Go To Start/All Programs/Adobe/Coldfusion 9 (multi server version)/ and right click on “Adobe ColdFusion 9 Administrator” and click on properties and change port to 8383 from 8300
18) Go To Start/All Programs/Adobe/Coldfusion 9 (multi server version)/ and right click on “JRun Management Console” and click on properties and change port to 8001 from 8000
19) Go To Start/All Programs/Adobe/Coldfusion 9 (multi server version)/ and run “Adobe ColdFusion 9 Administrator” by clicking on it
20) Enter admin password and let it run for first time and follow the on screen instruction
21) When it is ready – click ok
22) You will see CF Admin screen, now set up
a. Mail server
b. Custom Tags
c. CFX Tags
d. Data Sources
e. Or any other settings like debugging, mappings if you want to.
By loading a “*.car” file or manually
23) Open Apache Config file (httpd.conf), and go to the virtual host section of the web site you want to run under CF9 and copy and paste following three lines after the end of alias or before the
JRunConfig Apialloc false
JRunConfig Serverstore “C:/CF9Jrun4/lib/wsconfig/1/”
JRunConfig Bootstrap

Make sure you got the right path, though you won’t find any folder after lib and you shouldn’t be worried about this.
Save it and re-start Apache web server.

That’s it, happy CF9 server experience 

Categories: ColdFusion