我在表单中有一个表,其中填充了数据库中的文件名列表。表格中的每一行都有一个复选框。我希望能够在表中检查多行,然后提交表单。提交后,将根据检查的文件名删除每个数据库行。我还需要能够从服务器中删除此文件。我正在使用ColdFusion,我知道这将需要某种类型的cfloop,但我不确定实现它的最佳方法。
以下是表单的代码。
<cfform name="mainform"
action="deletingFiles.cfm?action=deleteDoc&teacherid=#url.teacherid#" method="post">
<table border="0" width="50%" id="product-table">
<tr>
<th>Check</th>
<th> Description </th>
<th>Date</th>
</tr>
<cfoutput query="delete">
<tr>
<td><input type="checkbox" name="DeleteID" value="#file_name#"></td>
<td><a href= "deletingFiles.cfm?action=editDoc">#description#</a></td>
<td>#DateFormat(date, "mmm-dd-yyyy")#</td>
</tr>
</cfoutput>
</table>
<center>
<button name="passchk" class="button blue" type="submit" >
<p> Delete Checked Items </p>
</button>
</center>
</cfform>
这是我从数据库和服务器删除文件的代码。现在它只会删除一个文件。
<cfif URL.action is "deleteDoc">
<cfquery name="deleteDoc" datasource="test" username="" password="">
delete from testdoc where file_name = '#form.DeleteID#'
</cfquery>
<cffile action = "delete"
file = "f:\inetpub\wwwroot\test\#form.DeleteID#">
</cfif>
提前感谢您提供任何帮助!
答案 0 :(得分:1)
基本答案如下:
<!--- This performs SQL delete even if there is no corresponding file --->
<cfquery name="deleteDoc" datasource="test" username="" password="">
delete
from testdoc
where file_name IN (<cfqueryparam cf_sql_type="varchar"
value="#form.DeleteID#" list="yes">)
</cfquery>
<cfloop index="i" list="#form.DeleteID#">
<!--- This code is vulnerable to attacks consider filtering out input --->
<cffile action = "delete"
file = "f:\inetpub\wwwroot\test\#i#">
</cfloop>