将文件保存到 Coldfusion 中的服务器,存储在 CF 临时目录中而不是指定的目的地
我在带有 Apache 和 MySQL 的 Ubuntu Linux 服务器上使用 Coldfusion 8。上传的任何文件都会存储在 Coldfusion 临时目录中: [/opt/coldfusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp17260.tmp] 我显然希望将其存储到 /var/www/cfm3/images [其中 #destination 的值#.我已经尝试过该网站提供的其他解决方案,但他们倾向于分叉到其他尚未解决我的解决方案的解决方案。下面是我的代码的示例。
<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
I'm using Coldfusion 8 on an Ubuntu Linux server with Apache and MySQL. Any file uploaded get stored in the Coldfusion temp directory:
[/opt/coldfusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp17260.tmp] I obviously want it to be stored in to /var/www/cfm3/images [which the value of #destination#. I have tried other solutions provided by this site but they tend to fork off to other solutions that have not solved my solution. Below is the an example of my code.
<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>
Any help would be greatly appreciated. :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有预感问题在于您如何创建
destination
变量,假设它是正确的(即使在创建之后),然后立即将其传递给 CFFILE。请参阅这个类似的问题(和解决方案):
将文件保存到ColdFusion中的服务器
在上面链接的这个问题中,回答者指出:
这与您所经历的行为非常相似 - 您希望该文件位于特定文件夹中,但它最终不会出现错误,而是位于“temp”目录中。
我会在模板中获得一些跟踪/调试信息,特别是在将目标变量的值提供给 CFFILE 之前。有些东西与您的描述不太相符,很可能是一条错误的路径,或者可能是它周围的权限。
I have a hunch the problem lies within how you are creating the
destination
variable, assuming it is correct (even after a create), and then immediately passing it to CFFILE.Refer to this similar question (and solution):
Saving File to Server in ColdFusion
In this question linked above, the answerer notes that:
This is very similar behavior to what you are experiencing--you want the file in a specific folder, but rather than error out, it ultimately lands in the "temp" dir.
I'd get some trace/debugging info in your template, specifically surrounding the value of the destination variable, prior to it being fed to CFFILE. Something doesn't quite gel with your description, and it could very well be a faulty path, or perhaps permissions surrounding it.
您是否收到类似于“上传未定义”的错误?如果是这样,请更改此行:
改为:
如果您没有收到该错误...您会得到什么输出?
编辑
另外,我个人不会将您的表单字段命名为简单的数字。尝试更改为:
注意字段名称之前的“用户”前缀。
Are you getting an error similar to "upload not defined"? If so, change this line:
To this:
If you aren't getting that error.... what output are you getting?
edit
Also, personally I wouldn't name your form fields as simple numbers. Try changing to this:
Note the "user" prefix before your field names.