在调用之前如何获取文件的文件名
<cffile action = "upload">
?我可以获取临时文件的文件名,但不能获取实际文件名。在 PHP 领域,我可以使用 $_FILES 超全局变量来获得我想要的东西 - 但据我所知,ColdFusion 中不存在这样的东西。
我可以在客户端获取文件名,但真的很想做这个服务器端。
谢谢
最佳答案
是的,这是可能的。在使用 cffile 标签之前,您可以使用此函数来获取客户端文件名:
<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:上传前获取文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/860964/