我在带有 Apache 和 MySQL 的 Ubuntu Linux 服务器上使用 Coldfusion 8。上传的任何文件都会存储在 Coldfusion 临时目录中: [/opt/coldfusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp17260.tmp] 我显然希望将其存储到/var/www/cfm3/images [其中 #destination 的值#.我已经尝试过该网站提供的其他解决方案,但他们倾向于 fork 到其他尚未解决我的解决方案的解决方案。下面是我的代码的示例。
<cfset destination = expandPath("images") />
<cfif not directoryExists(destination)>
<cfdirectory action="create" directory="#destination#">
</cfif>
<cfloop from="1" to="#num_users#" index="i">
<cfoutput>User #i# Photo Upload :
<cfif isDefined("#i#")>
<cffile action="upload"
fileField="#i#"
accept="image/jpeg, image/gif, image/png"
destination="#destination#"
nameConflict="makeUnique"
mode = 777>
<cfdump var="#upload#">
<p>Thank you, your file has been uploaded.</p>
</cfif>
<input type="file" name="#i#" /><br />
</cfoutput>
</cfloop>
如有任何帮助,我们将不胜感激。 :D
最佳答案
我有预感,问题在于您如何创建 destination
变量,假设它是正确的(即使在创建之后),然后立即将其传递给 CFFILE。
引用这个类似的问题(和解决方案):
Saving File to Server in ColdFusion
在上面链接的这个问题中,回答者指出:
The destination has to be a full path, otherwise it gets sent to a directory relative to the temp directory of Cold Fusion [sic].
这与您遇到的行为非常相似 - 您希望文件位于特定文件夹中,但它最终不会出现错误,而是位于“temp”目录中。
我会在模板中获得一些跟踪/调试信息,特别是在将目标变量的值馈送到 CFFILE 之前。有些东西与您的描述不太相符,很可能是路径错误,或者可能是围绕它的权限。
关于mysql - 将文件保存到 Coldfusion 中的服务器,存储在 CF 临时目录中而不是指定的目的地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8393717/