coldfusion cffile上传给出了奇怪的错误信息

时间:2016-07-16 23:33:48

标签: coldfusion upload cffile

我正在使用动作上传来测试cffile。我编写了一个正确上传的程序,但它也向我发送了一条错误消息。该消息似乎是错误的,但我无法弄清楚需要修复的内容。该计划:

<form method="post" enctype="multipart/form-data"
name="uploadForm"  action= "#reppath#demos">
<input name="FileContents" type="file" >
<input name="submit" type="submit" value="Upload File"> 
</form>

<cffile action = "upload"
fileField     = "FileContents"
destination   = "#reppath#/demos" 
nameConflict  = "MakeUnique"> 

错误:

 Invalid content type: ''.
 The cffile action="upload" requires forms to use enctype="multipart/form-data".

 The error occurred in /opt/coldfusion8/wwwroot/reports/frag5.cfm: line 20

 18 : <cffile action = "upload"
 19 : fileField     = "FileContents"
 20 : destination   = "#reppath#/demos" 
 21 : nameConflict  = "MakeUnique"> 

表单确实包含enctype =&#34; multipart / form-data&#34;所以我不明白为什么我会收到这个错误。上传工作正常,并将所选文件发送到目标文件夹。

1 个答案:

答案 0 :(得分:1)

嗯,我找到了,但这不是你所期待的。 Sagar Ganatra写道:“所以CF尝试在上传任何内容之前运行上传代码,导致您看到的错误。要修复它,请添加额外的检查以确保该变量不为空且它应该正常工作。”这是有效的:

<cfif IsDefined("form.FileContents") then <cffile action = "upload">. 

问题现在消失了。见https://www.experts-exchange.com/questions/27838969/CFFILE-UPLOAD-ENCTYPE-ERROR.html