ColdFusion – get file name before cffile upload

<cffunction name="getClientFileName" returntype="string" output="false" hint="">
	<cfargument name="fieldName" required="true" type="string" hint="Name of the Form field" />

	<cfset var tmpPartsArray = Form.getPartsArray() />

	<cfif IsDefined("tmpPartsArray")>
		<cfloop array="#tmpPartsArray#" index="local.tmpPart">
			<cfif local.tmpPart.isFile() AND local.tmpPart.getName() EQ arguments.fieldName>
				<cfreturn local.tmpPart.getFileName() />
			</cfif>
		</cfloop>
	</cfif>

	<cfreturn "" />
</cffunction>

source: http://www.stillnetstudios.com/get-filename-before-calling-cffile/


Comments are closed.