ColdFusion:上传前获取文件名

标签 coldfusion file-upload

在调用之前如何获取文件的文件名

<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/

相关文章:

jquery文件上传插件提交整个表单

javascript - 在没有 JavaScript 上传的情况下显示文件上传进度

tomcat - java.io.FileNotFoundException(访问被拒绝),文件写在@MultipartConfig(location)中

java - 使用 jsp 和 servlet 上传多个文件

coldfusion - 如何处理CFLOCK超时错误?

coldfusion - 读取 CF9 中的 Application.DataSource

arrays - 将 ColdFusion session 转换为数组(日期)正则表达式问题

javascript - 二进制解码为 JavaScript

java - gwt上传: Set dynamic file upload size

apache - Coldfusion 11 REST 服务适用于 HTTP 但不适用于 HTTPS (404)