coldfusion cffile上传如何描述要上传的文件

时间:2016-07-15 18:23:26

标签: coldfusion cffile

我从未使用过cffile上传。在查看文档时,我看到要上载的文件被描述为

用于选择文件的表单字段的名称。 请勿使用数字符号(#)指定字段名称。

我无法解读这个。如果要上传的文件是john.jpg,驻留在用户的磁盘上,如何在cffile命令中指明?

我还有其他问题,但我想从这个非常基本的问题开始。

2 个答案:

答案 0 :(得分:1)

您使用的是哪些文档?应该有一个例子,例如:<cffile action="upload">

在此示例中(我已编辑过),它显示您没有引用用户所选文件的名称,可能是任何内容,您引用表单字段的名称< / strong>,fileContents,用于上传文件。

<!--- Windows Example --->
<!--- Check to see if the Form variable exists. --->
<cfif structKeyExists(Form, "FileContents") > 
    <!--- If TRUE, upload the file. --->
    <cffile action = "upload"
        fileField = "FileContents"
        destination = "c:\files\upload\" 
        accept = "text/html"
        nameConflict = "MakeUnique"> 
<cfelse> 
    <!--- If FALSE, show the Form. --->
    <form method="post" action=<cfoutput>#cgi.script_name#</cfoutput>
         name="uploadForm" enctype="multipart/form-data"> 

        <input name="FileContents" type="file"> 
        <input name="submit" type="submit" value="Upload File"> 
    </form> 
</cfif>

CFFILE进程完成后,会在名为CFFILE的结构中定义变量集合(请参阅文档链接)。其中一个变量是cffile.clientFile,其中包含从用户计算机上传的文件的名称。

答案 1 :(得分:0)

对于cffile命令:

<cffile action = "upload"
        fileField = "FileContents"
        destination = "c:\files\upload\" 
        accept = "text/html"
        nameConflict = "MakeUnique"
        result = "thisResult">

...你会使用#hisResult.clientFile#来获取原始文件名。 所有其他字段也可以使用它。

我在stackoverflow上发现了这个: ColdFusion ServerFile is undefined in CFFile