Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated the ColdFusion code.

Should now work in IE for single form posts.
commit 14ebbcf23e48318e457fc57d6640c64a5e522ed6 1 parent 33d0c2f
@PegWeb PegWeb authored
View
1  server/coldfusion/coldfusion.cfc
@@ -1 +0,0 @@
-<!---
View
1  server/coldfusion/demo.cfm
@@ -1 +0,0 @@
-<!DOCTYPE html>
View
72 server/coldfusion/image-uploader.cfc
@@ -0,0 +1,72 @@
+<!--- Code provided by Pegasus Web Productions LLC - www.pegweb.com --->
+<!--- get stuck use the forums http://github.com/valums/file-uploader --->
+<!--- Tested with Adobe CF Enterprise 9.x and Valum's AJAX uploader 2.0 --->
+
+<cfcomponent hint="I do your uploads from the valum AJAX uploader">
+
+ <!--- function for single file submission uploads where XHR is not supported ex: IE --->
+ <cffunction name="Upload" access="remote" output="false" returntype="any" returnformat="JSON">
+ <cfargument name="qqfile" type="string" required="true">
+
+ <cfset var local = structNew()>
+ <cfset local.response = structNew()>
+ <cfset local.requestData = GetHttpRequestData()><!--- get the request headers and body --->
+ <cfset UploadDir = ""><!--- set your upload directory here ex: c:\website\www\images\ --->
+
+
+ <!--- check if XHR data exists --->
+ <cfif len(local.requestData.content) GT 0>
+
+ <cfset local.response = UploadFileXhr(arguments.qqfile, local.requestData.content)>
+
+ <cfelse><!--- no XHR data so process this as standard form submission --->
+
+ <!--- upload the file --->
+ <cffile action="upload" fileField="form.qqfile" destination="#UploadDir#" nameConflict="makeunique">
+
+ <!--- populate our structure with information about the image we just uploaded in case we want to use this later for CFIMAGE tags or any other processing --->
+ <cfset local.metaData = {
+ clientFile = FILE.clientFile,
+ clientFileExt = FILE.clientFileExt,
+ clientFileName = FILE.clientFileName,
+ contentSubType = FILE.contentSubType,
+ contentType = FILE.contentType,
+ fileSize = FILE.fileSize
+ } />
+ <!--- return the response --->
+ <cfset local.response['success'] = true>
+ <cfset local.response['type'] = 'form'>
+ </cfif>
+
+ <cfreturn local.response>
+ </cffunction>
+
+ <!--- function for browsers that support XHR ex: Almost anything but IE --->
+ <cffunction name="UploadFileXhr" access="private" output="false" returntype="struct">
+ <cfargument name="qqfile" type="string" required="true">
+ <cfargument name="content" type="any" required="true">
+
+ <cfset var local = structNew()>
+ <cfset local.response = structNew()>
+ <cfset UploadDir = ""><!--- set your upload directory here ex: c:\website\www\images\ --->
+
+ <!--- write the contents of the http request to a file. The filename is passed with the qqfile variable --->
+ <cffile action="write" file="#UploadDir#\#arguments.qqfile#" output="#arguments.content#" nameConflict="makeunique">
+
+ <!--- populate our structure with information about the image we just uploaded in case we want to use this later for CFIMAGE tags or any other processing --->
+ <cfset local.metaData = {
+ clientFile = FILE.clientFile,
+ clientFileExt = FILE.clientFileExt,
+ clientFileName = FILE.clientFileName,
+ contentSubType = FILE.contentSubType,
+ contentType = FILE.contentType,
+ fileSize = FILE.fileSize
+ } />
+
+ <!--- return custom JSON if desired--->
+ <cfset local.response['success'] = true>
+ <cfset local.response['type'] = 'xhr'>
+ <cfreturn local.response>
+ </cffunction>
+
+</cfcomponent>
View
17 server/coldfusion/readme.txt
@@ -1,9 +1,12 @@
-Coldfusion example by Sidney Maestre
-http://www.designovermatter.com/post.cfm/ajax-file-uploader-for-coldfusion
+Coldfusion example by Patrick Hedgepath - Pegasus Web Productions LLC - www.pegweb.com
- 1. Unzip Andrew's AJAX Uploader into your web root.
- 2. Replace the demo.htm with demo.cfm in the "client" folder
- 3. Place coldfusion.cfc in the "server" folder
- 4. Browse to the demo.cfm file and try it out. The file should be written to the "server" folder.
+Code has been tested with version 2.0 of Valum's AJAX file uploader on Cold Fusion Enterprise 9.x server
+If you have any improvements to this code please feel free to email them to me webmaster@pegweb.com
-Questions? You can contact Sidney Maestreme by mail (sid.maestre(at)designovermatter.com) or Twitter @SidneyAllen
+ 1. Unzip Valum's AJAX Uploader into your web root.
+ 2. Use the upload-page.cfm in place of the demo.htm file found in the "client" folder
+ 3. Open the image-uploader.cfc and edit the lines in each function that say <cfset UploadDir = ""> to include the path you want the images to upload to on the server.
+ 4. Place image-uploader.cfc in the same folder on the server and the upload-page.cfm file
+ 5. Browse to the upload-page.cfm file and test it out.
+
+Questions, problems, comments? Go to the forums and post https://github.com/valums/file-uploader
View
45 server/coldfusion/upload-page.cfm
@@ -0,0 +1,45 @@
+<!--- Code provided by Pegasus Web Productions LLC - www.pegweb.com --->
+<!--- get stuck use the forums http://github.com/valums/file-uploader --->
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <link href="fileuploader.css" rel="stylesheet" type="text/css">
+ <script src="fileuploader.js" type="text/javascript"></script>
+ <script type="text/javascript">
+ $().ready(function() {
+ var running = 0; // create an increment counter
+ var uploader = new qq.FileUploader({
+ element: document.getElementById('file-uploader'),
+ action: 'image-uploader.cfc',
+ params: {
+ method: 'Upload',
+ allowedExtensions: ['jpg', 'jpeg', 'gif'],
+ sizeLimit: 5000,
+ debug: true},
+ onSubmit: function(id, fileName){
+ running++; //increment the counter for each image submission
+ },
+ onComplete: function (id, filename, responseJSON) {
+ running--;
+ if(running == 0){
+ window.location = "upload-page.cfm"; // I send them to this page once all images complete uploading
+ }
+ }
+ });
+ });
+ </script>
+</head>
+<body >
+ <h1>ColdFusion File Uploader Demo</h1>
+ <p><a href="http://github.com/valums/file-uploader">Back to project page</a></p>
+
+ <div id="file-uploader">
+ <noscript>
+ <p>Please enable JavaScript to use the file uploader.</p>
+ <!-- or put a simple form for upload here -->
+ </noscript>
+ </div>
+
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.