Monthly Archives: February 2011

Back by popular demand


My demo site has been down for quite some time.  Many of the code samples I have zipped up and tucked away so people could download them have become quite stale.  Many do not work at all any more without some minor modifications.  The world goes on it would seem.

To get things off on the right foot, I have gotten the demo site back online.  For those who do not know the url point your web browser to http://demos.kisdigital.com.

I recently had some questions pertaining to my simple CF chat application so I made it a priority to get it up and running first.  I can say beyond a shadow of a doubt it is working for Firefox, Chrome, and Internet Exploder 8.  I tested it on these browsers this afternoon.

The demo site itself is looking pretty rough.  I plan to get a framework up and running for it this weekend some time.

Demo ajaxProxy.cfc for uploading files


A reader noted he was having some problems working with my simple jQuery multi-file uploader.  He asked that I post the ajaxProxy that handles file submissions, so here is the stripped down version:

<cfcomponent output="no"> 
 <cffunction name="Upload" access="remote" returntype="struct" output="yes" returnFormat="JSON" >  
  <cfscript>   
    var base = '/var/www/localhost/';   
    var filePath = base;   
    var thumbPath = base & '/thumbs';   
    var newfile = '';   
    var height = 0;   
    var width = 0;   
    var imgObj = '';   
    var imgStruct = structNew();   
    var response = structNew();   
    var resizeParent = false;   

    response['svrCode'] = '0';   
    response['svrMessage'] = 'Upload successful';  
   </cfscript>  
   <cfsetting requesttimeout="300" />  
   <cftry>   
    <cfif filePath is base>    
     <cfthrow message="Invalid file path" />   
    </cfif>   
    <cfif not DirectoryExists(filePath)>     
      <cfdirectory action="create" directory="#filepath#" />   
    </cfif>   
    <cfif not DirectoryExists(thumbPath)>    
     <cfdirectory action="create" directory="#thumbPath#" />   
    </cfif>   
    <cffile action="upload" filefield="filename" destination="#filePath#" accept="image/jpeg,image/gif,image/x-png,image/pjpeg" nameconflict="MakeUnique" />   
    <cfset newfile="#CreateUUID()#.#cffile.ServerFileExt#" />   
    <cffile action="rename" source="#filePath#/#cffile.serverfile#" destination="#filePath#/#newfile#" />   
    <cfimage action="read" source="#filePath#/#newfile#" name="uploadedFile" />   
    <cfset width = ImageGetWidth(uploadedFile) />   
    <cfset height = ImageGetHeight(uploadedFile) />   
    <cfif (width gt 1024) or (height gt 768)>    
     <cfif width gt height>     
      <cfimage action="resize" width="1024" height="" source="#uploadedFile#" destination="#filePath#/#newfile#" overwrite="true" />    
     <cfelse>     
      <cfimage action="resize" width="" height="768" source="#uploadedFile#" destination="#filePath#/#newfile#" overwrite="true" />    
     </cfif>   
    </cfif>   
   <cfif width gt height>    
    <cfimage action="resize" width="150" height="" source="#uploadedFile#" destination="#thumbPath#/#newfile#" overwrite="true" />   
   <cfelse>    
    <cfimage action="resize" width="" height="150" source="#uploadedFile#" destination="#thumbPath#/#newfile#" overwrite="true" />   
   </cfif>   
   <cfcatch type="any">    
    <cfscript>     
      response['svrCode'] = "-1";     
      response['svrMessage'] = "Error uploading file to the server!";    
    </cfscript>   
   </cfcatch>  
  </cftry>  
  <cfreturn response> 
 </cffunction>
</cfcomponent>

This handles uploading an image and resizing.