PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/php/server/coldfusion/image-uploader.cfc

https://bitbucket.org/akatsaris/paoshopgr
ColdFusion CFScript | 72 lines | 56 code | 16 blank | 0 comment | 6 complexity | 622f5334e0896f2427a609c889878042 MD5 | raw file
  1. <!--- Code provided by Pegasus Web Productions LLC - www.pegweb.com --->
  2. <!--- get stuck use the forums http://github.com/valums/file-uploader --->
  3. <!--- Tested with Adobe CF Enterprise 9.x and Valum's AJAX uploader 2.0 --->
  4. <cfcomponent hint="I do your uploads from the valum AJAX uploader">
  5. <!--- function for single file submission uploads where XHR is not supported ex: IE --->
  6. <cffunction name="Upload" access="remote" output="false" returntype="any" returnformat="JSON">
  7. <cfargument name="qqfile" type="string" required="true">
  8. <cfset var local = structNew()>
  9. <cfset local.response = structNew()>
  10. <cfset local.requestData = GetHttpRequestData()><!--- get the request headers and body --->
  11. <cfset UploadDir = ""><!--- set your upload directory here ex: c:\website\www\images\ --->
  12. <!--- check if XHR data exists --->
  13. <cfif len(local.requestData.content) GT 0>
  14. <cfset local.response = UploadFileXhr(arguments.qqfile, local.requestData.content)>
  15. <cfelse><!--- no XHR data so process this as standard form submission --->
  16. <!--- upload the file --->
  17. <cffile action="upload" fileField="form.qqfile" destination="#UploadDir#" nameConflict="makeunique">
  18. <!--- 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 --->
  19. <cfset local.metaData = {
  20. clientFile = FILE.clientFile,
  21. clientFileExt = FILE.clientFileExt,
  22. clientFileName = FILE.clientFileName,
  23. contentSubType = FILE.contentSubType,
  24. contentType = FILE.contentType,
  25. fileSize = FILE.fileSize
  26. } />
  27. <!--- return the response --->
  28. <cfset local.response['success'] = true>
  29. <cfset local.response['type'] = 'form'>
  30. </cfif>
  31. <cfreturn local.response>
  32. </cffunction>
  33. <!--- function for browsers that support XHR ex: Almost anything but IE --->
  34. <cffunction name="UploadFileXhr" access="private" output="false" returntype="struct">
  35. <cfargument name="qqfile" type="string" required="true">
  36. <cfargument name="content" type="any" required="true">
  37. <cfset var local = structNew()>
  38. <cfset local.response = structNew()>
  39. <cfset UploadDir = ""><!--- set your upload directory here ex: c:\website\www\images\ --->
  40. <!--- write the contents of the http request to a file. The filename is passed with the qqfile variable --->
  41. <cffile action="write" file="#UploadDir#\#arguments.qqfile#" output="#arguments.content#" nameConflict="makeunique">
  42. <!--- 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 --->
  43. <cfset local.metaData = {
  44. clientFile = FILE.clientFile,
  45. clientFileExt = FILE.clientFileExt,
  46. clientFileName = FILE.clientFileName,
  47. contentSubType = FILE.contentSubType,
  48. contentType = FILE.contentType,
  49. fileSize = FILE.fileSize
  50. } />
  51. <!--- return custom JSON if desired--->
  52. <cfset local.response['success'] = true>
  53. <cfset local.response['type'] = 'xhr'>
  54. <cfreturn local.response>
  55. </cffunction>
  56. </cfcomponent>