<cffile action ="write">拒绝工作

Jos*_*a M 1 coldfusion cffile

我把我的头发拉到这里,真的无法弄清楚为什么这段代码不起作用.我需要用来<cffile action="write">将文档放在服务器上.

我已经将代码剥离到最低限度,试图让文件写入服务器,但它仍然不会让步.我正在运行的代码就是这个.

<cffile action = "write" 
        file = "test.txt"
        output = "Content"
>
Run Code Online (Sandbox Code Playgroud)

当我在服务器上运行此代码时,它什么都不做.我在屏幕上没有收到任何错误消息,但服务器上也没有出现任何文件.

我一直在寻找一段时间,我唯一能想到的就是编写绝对文件路径,所以我也试过这个

<cffile action = "write" 
        file = "http://www.my_url.com/test.txt"
        output = "Content"
>
Run Code Online (Sandbox Code Playgroud)

这会给我一个错误消息(见下文),但是搜索如何对此错误消息进行排序却不太有用.

An error occurred when performing a file operation write on file 
http://www.my_url.com/test.txt.
The cause of this exception was: java.io.FileNotFoundException:  
http://www.my_url.com/test.txt.
Run Code Online (Sandbox Code Playgroud)

我认为这可能是我的权限的问题,但是在FileNotFound的末尾没有" 访问被拒绝 "错误,所以我真的迷失了该怎么做.

这是双重真气,因为在这个确切的网站上我也使用<cffile action="upload">哪个工作绝对正常!

Lei*_*igh 6

如上所述,cffile仅在服务器文件系统上运行.因此,您需要使用物理文件路径,而不是URL.此外,文档说如果您使用相对路径,文件将写入:

"...(一个路径)相对于ColdFusion临时目录,由GetTempDirectory函数返回."

因此,如果您没有收到错误,则创建文件,而不是您预期的位置.为避免这种混淆,请使用绝对路径:

    <cffile action="write" file="c:/path/to/test.txt" output="Content">
Run Code Online (Sandbox Code Playgroud)