ColdFusion:在上传之前获取文件的名称 [英] ColdFusion: get the name of a file before uploading
问题描述
在我调用
How can I get the filename of a file before I call the
<cffile action = "upload">
?我可以得到临时文件的文件名,但不是实际的文件名。在PHP的土地,我可以使用$ _FILES超全球得到我想要的 - 但据我可以告诉没有这样的事情存在于ColdFusion。
? I can get the filename of the temp file, but not of the actual filename. In PHP land I can use the $_FILES superglobal to get what I want - but as far as I can tell no such thing exists in ColdFusion.
我可以得到文件名客户端,但真的要做这个服务器端。
I can get the filename client-side but would really want to do this server side.
谢谢
Thanks
推荐答案
是的,这是可能的。您可以在使用cffile标签之前使用此函数获取客户端文件名:
Yes this is possible. You can use this function to grab the client file name before using the cffile tag:
<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>
更多信息: http://www.stillnetstudios.com/get-filename-before-calling-cffile/
这篇关于ColdFusion:在上传之前获取文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!