我有一个小页面,其中有一个包含几个字段的表单。还包括文件上传功能。提交表单时,我需要能够将要上传的文件的文件名插入到“sURL”字段中。(可以使用此文件名自动填充 sURL 字段,如果它是外部 URL,也可以手动输入)。我看过其他有这个问题的人,似乎没有直接的解决方法?有没有人能解释一下?
<html><head>
<title>New Survey Entry</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
function check ( form )
{
if (form.ul_path.value == "") {
alert( "Please select the file to upload." );
form.ul_path.focus();
return false ;
}
return true ;
}
</script>
<CFIF NOT isDefined("dir")>
<CFSET dir = "">
</CFIF>
<CFIF NOT isDefined("clientFile")>
<CFSET clientFile = "">
</CFIF>
<CFQUERY NAME="getpub" DATASOURCE="testpage" DBTYPE="ODBC">
SELECT *
FROM surveypubs
ORDER BY sGroup asc
</CFQUERY>
<h2><center>NEW SURVEY ENTRY</center></h2>
<table cellpadding="3" cellspacing="3" class="font13">
<cfoutput>
<form name="input" enctype="multipart/form-data" action="index.cfml?cat=test&page=insertSurvey" method="post">
<tr>
<td valign="middle" align="left"><b>Year:</b></td>
<td colspan="3"><input name="sYear" type="text" size="8" value="<CFOUTPUT>#year(now())#</CFOUTPUT>"><input name="sYear_required" type="hidden" value="You must enter a Year."></td>
</tr>
</cfoutput>
<tr>
<td valign="middle" align="left"><b>Group:</b></td>
<td colspan="3"> <select name="sGroup">
<option value="">--- Select One ---</option>
<cfoutput query="getpub"><option value="#sGroup#">#sGroup#</option></cfoutput>
</select> <br> Don't see the Survey Group? Click <a href="/index.cfml?cat=test&page=inputgroup" target="_blank">here</a> to add.
</td>
</div><br><br>
</tr>
<tr>
<td valign="middle" align="left"><b>Title:</b></td>
<td colspan="3"><input name="sTitle" type="text" size="85"><input name="sTitle_required" type="hidden" value="You must enter a Title."></td>
</tr>
<tr>
<td valign="middle" align="left"><b>Comment:</b></td>
<td colspan="3"><input name="sComment" type="text" size="85"></td>
</tr>
<tr>
<td valign="middle" align="left"><b>URL:</b></td>
<td colspan="3"><input name="sURL" type="text" size="85"></td>
</tr>
<td valign="bottom" align="left"><b>URL Type:</b></td>
<td colspan="3">
<input type="radio" name="surlType" value="0" checked> Internal <input type="radio" name="surlType" value="1"> External</td>
</tr>
<cfoutput>
<input name="dateAdded" type="hidden" value="#dateformat(now(),"mm-dd-yyyy")#">
</cfoutput>
<tr>
<td></td>
<form action="/index.cfml?cat=test&page=inputSurvey" method="POST" enctype="multipart/form-data" name="upload_form" id="upload_form" onsubmit="return check(this);">
<CFIF structKeyExists(form, "ul_path") and len(form["ul_path"])>
<CFFILE ACTION="UPLOAD" FILEFIELD="ul_path" DESTINATION="D:\testpage\docs\" NAMECONFLICT="OverWrite">
<CFSET ClientFilePath = "#clientDirectory#\#clientFile#">
</CFIF>
<td colspan="3" align="left">Click on the Browse button to select the file to Upload:<br>
<input type="file" name="ul_path" id="ul_path" style="height: 22px;width: 350px;" value=""></td>
</tr>
<tr>
<td></td>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit"> <input name="clear" value="Clear" type="reset"> <input type="button" name="back" value="Back" class="input" onClick="javascript:history.back();"></td>
</tr>
</table>
</form>
<cfif isDefined("CFFILE.ClientFile")>
<cfset form.sURL = "#CFFILE.ClientFile#">
<cfelse>
<cfset form.sURL = "null">
</cfif>
<cfoutput><input type="hidden" name="sURL" id="sURL" value="http://testpage.com/docs/#ClientFile#"/></cfoutput>
</form>
</body>
</html>