문제

I have a table within a form that is populated with a list of file names from a database. Each row in the table has a checkbox. I would like to be able to check multiple rows with in the table and then submit the form. Once submitted, each database row would be deleted based upon the file name that was checked. I would also need to be able to delete this file from the server as well. I am using ColdFusion and I know this is going to require some type of cfloop, but I am not sure of the best way to make it happen.

Here is the code for the form.

<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>&nbsp;&nbsp;Delete Checked Items&nbsp;&nbsp;</p>
        </button>
    </center>
</cfform>

This is my code for deleting the files from the database and the server. Right now it will only delete one file.

<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>

Thank you in advance for any help you can provide!

도움이 되었습니까?

해결책

The basic answer is something like:

<!--- 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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top