在ColdFusion中将文件保存到服务器

The*_*Man 2 coldfusion file-upload

做了一些研究后,我觉得这应该有效,但是它没有将文件保存到我的Images目录中.

    <cfform name="uploadImgForm" method="post" action="#CGI.PATH_INFO#?#CGI.QUERY_STRING#" enctype="multipart/form-data">
    <input name="txtImg" type="file" />
    <input name="btnSubmit" type="submit" />
</cfform>
<cfif isDefined("Form.txtImg")>
    <cffile action="upload"
        fileField = "txtImg"
        destination="/Images"
        accept="image/jpeg"
        nameconflict="makeunique">
</cfif>
Run Code Online (Sandbox Code Playgroud)

我打算做一些验证,但我想先把这个简单的例子搞定.

我之后遇到过这个问题,在上传之前尝试重命名文件时很有用: Adobe链接

小智 5

目标必须是完整路径,否则它将被发送到相对于ColdFusion临时目录的目录.

试试这个:

<cfset destination = expandPath("Images") />

<cffile action="upload"
    fileField = "txtImg"
    destination="#destination#"
    accept="image/jpeg"
    nameconflict="makeunique">
Run Code Online (Sandbox Code Playgroud)