<!---
AJAX FileUploader for ColdFusion
version: 1.1
feedback:
[email protected]--->
<cfcomponent hint="I handle AJAX File Uploads from Valum's AJAX file uploader library">
<cffunction name="Upload" access="remote" output="false" returntype="any" returnformat="JSON" >
<cfargument name="qqfile" type="string" required="true">
<cfset x = GetHttpRequestData()>
<!--- check if XHR data exists --->
<cfif len(x.content) gt 0>
<cfreturn UploadFileXhr(arguments.qqfile,x.content) />
<cfelse>
<!--- no XHR data process as standard form submission --->
<cffile action="upload" fileField = "qqfile" destination ="#ExpandPath('.')#" nameConflict = "makeunique" />
<cfset msgStruct['success']= true />
<cfset msgStruct['type']= 'form' />
<cfreturn serializeJSON(msgStruct) />
</cfif>
</cffunction>
<cffunction name="UploadFileXhr" access="private" output="false" returntype="any">
<cfargument name="qqfile" type="string" required="true">
<cfargument name="content" type="any" required="true">
<!--- write the contents of the http request to a file.
The filename is passed with the qqfile variable --->
<cffile action="write" file="#ExpandPath('.')#/#arguments.qqfile#" output="#content#" >
<!--- if you want to return some JSON you can do it here.
I'm just passing a success message --->
<cfset msgStruct['success']= true />
<cfset msgStruct['type']= 'xhr' />
<cfreturn serializeJSON(msgStruct) />
</cffunction>
</cfcomponent>
0 commit comments