我在表单中有2个提交按钮。当我点击一个“上传”按钮时,我将上传一个文件并保存在服务器的文件路径中。当我点击另一个名为“Process”的按钮时,我想在代码中使用这个文件路径。当我单击该过程时,在下面的代码中没有发生任何转储。表格提交给自己。有没有更好的方法来做到这一点。提前谢谢。
<table width="40%" border="0" style="border: 1px solid black;">
<form name="uploadform" action="processfile.cfm" enctype="multipart/form-data"
method="post">
<tr>
<td><input type="file" name="FileContents" size="25">
<input type="button" name="action" id="action" value="Upload">
</td>
</tr>
<tr>
<td align="middle">
<input type="button" name="submitaction" id="process" value="Process">
</td>
</tr>
</form>
</table>
<!---Clicking the fist button to upload--->
<cfset variables.filepath ="">
<cfif isdefined("form.action") AND form.action eq "upload">
<cffile action = "upload" fileField = "FileContents" destination = "C:\test\" accept = "text/plain" nameConflict="overwrite">
<cfset variables.filepath= "C:\test\#cffile.serverFile#">
<!---Clicking the second button to process--->
<cfelseif isdefined("form.submitaction") AND form.submitaction eq "process">
<cfdump var="#variables.filepath#">
</cfif>
答案 0 :(得分:3)
您的转储未发生的原因是<input type="button">
除非您通过JavaScript执行此操作,否则不会提交表单。
请阅读Difference between <input type='button' /> and <input type='submit' />
答案 1 :(得分:0)
您可以尝试以下代码。这也会转储路径的值。
<cfif isDefined('Form.tmpfile1')>
<cfset root = ExpandPath("/Upload")><!---location where file should be uploaded--->
<cfset filename=GetFileFromPath(Form.tmpFile1)>
<cfset FileExt=ListLast(filename,".")>
<cfset variables.filepath ="">
<cfset filename = "BidDocument1." & FileExt>
<cffile action="upload"
filefield="BidDoc1"
destination="C:\Upload\"
nameconflict="overwrite"
accept="application/pdf,application/msword,application/vnd.ms-excel,text/plain,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
<cfset variables.filepath= "C:\test\#cffile.serverFile#">
<cfdump var="#variables.filepath#">
</cfif>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cffileupload Document</title>
<form name="form1" enctype="multipart/form-data" method="post">
<input type="hidden" name="tmpfile1" value="" />
<input type="file" name="BidDoc1" onchange="setFile(this.form);" />
<input type="submit" name="save1" value="Upload" />
</form>
<button onclick="location.href='processfile.cfm'">Process</button>
</html>
这应该对你有帮助。