How to delete and download attachments?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bonneylake
    Contributor
    • Aug 2008
    • 769

    How to delete and download attachments?

    Hey Everyone,

    Well for the last few days i been trying to figure out how to delete attachments and download attachments to my computer. The deleting is sort of working and i don't know where to begin on downloading. Right now with the deleting it will delete from the attachments folder on the server but it does not delete from the database an was wondering if someone could explain what i am doing wrong on deleting attachments and how i could make it where a user could download an attachment to there computer? Here is what i have.

    Code:
    <cfparam name="form.confirmed" default="0">
        
    <cfquery name="attachment" datasource="CustomerSupport">
             SELECT fk_ticketID,description,path
             FROM dbo.tbl_CS_attachments
             WHERE fk_ticketID = #URL.pk_ticketID#
    </cfquery>
    
    
    <form method="post">
    <cfoutput query="ticket">
    <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
    </cfoutput>
    <cfoutput query="attachment">
    <input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
    </cfoutput>
    
    <cfoutput query="attachment">
    #description#
    <a href="attachments/#path#" target="_blank" >view</a>
    <br>
    <cfif form.confirmed EQ 1>
    <cflock timeout="60">
    <cffile action="delete" 
    file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
    </cflock>
    </cfif>
    <input type="hidden" name="confirmed" value="1">
    <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
    <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
    </cfoutput>
    </form>
    Thank you,
    Rach
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    We'll deal with one thing at a time. Deleting first. Where's the delete query?

    Comment

    • bonneylake
      Contributor
      • Aug 2008
      • 769

      #3
      Originally posted by acoder
      We'll deal with one thing at a time. Deleting first. Where's the delete query?
      Hey Acoder,

      Well i had a delete query but i took it out because it kept deleting my files. If i went to view it, it would work right the first time but if i refreshed it deleted it. Or else if i went to view the file again it would be deleted. But here is what i did have

      Code:
      <cfquery name="deleteattachment" datasource="CustomerSupport">
               DELETE 
               FROM dbo.tbl_CS_attachments
               WHERE fk_ticketID = #URL.pk_ticketID#
      </cfquery>
      an i think i figured out the download, just not sure what to put for destination. but here is what i had come up with for the download part.

      Code:
      <cflock timeout="60">
      <cffile action="copy" 
      source="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" destination="">
      </cflock>
      Thank you,
      Rach

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        The delete query should go next to the actual delete operation (cffile).

        When you say download, you mean a download to the user's computer? cffile action="copy" wouldn't do this. You need to set a content-disposition header.

        Comment

        • bonneylake
          Contributor
          • Aug 2008
          • 769

          #5
          Originally posted by acoder
          The delete query should go next to the actual delete operation (cffile).

          When you say download, you mean a download to the user's computer? cffile action="copy" wouldn't do this. You need to set a content-disposition header.

          Hey Acoder,

          Yes i mean to download to the computer. But how would i set the content-disposition header?

          An ok so the delete query should be like this?

          Code:
          <cfif form.confirmed EQ 1>
          
          <cflock timeout="60">
          <cffile action="delete" 
          
          <cfquery name="deleteattachment" datasource="CustomerSupport">
                   DELETE 
                   FROM dbo.tbl_CS_attachments
                   WHERE fk_ticketID = #URL.pk_ticketID#
          </cfquery>
          file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
          </cflock>
          </cfif>
          Thank you,
          Rach

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Not inside the cffile (that'd result in an error). Next to it, either before or after.

            As for the header, use cfheader. You should find something in the docs.

            Comment

            • bonneylake
              Contributor
              • Aug 2008
              • 769

              #7
              Originally posted by acoder
              Not inside the cffile (that'd result in an error). Next to it, either before or after.

              As for the header, use cfheader. You should find something in the docs.

              Hey Acoder,


              I found this doc on it http://livedocs.adobe.com/coldfusion...e=00000232.htm
              so basically according to it i need to do something like this?

              Code:
              <cfcontent 
              file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
              deleteFile = "no">
              an the delete is working beautifully. But i was wondering if there was a way that after they deleted one a message would appear saying it had been deleted an also show that the file didn't exist anymore. Because right now when i delete it still shows the file until i click refresh.

              Thank you,
              Rach

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Put the delete query first before running any queries showing the attachments.

                Comment

                • bonneylake
                  Contributor
                  • Aug 2008
                  • 769

                  #9
                  Originally posted by acoder
                  Put the delete query first before running any queries showing the attachments.
                  Hey Acoder,

                  So your saying move the delete above the view because this is how i have it right now.

                  Code:
                  <form method="post">
                  <table style="100%" class="ticketlist">
                  <col style="width:10%;" />
                  <col style="width:3%;" />
                  <col style="width:3%;" />
                  <thead>
                  <tr class="attachment" >
                  <th>Attachment</th>
                  <th>View</th>
                  <th>Download</th>
                  </tr>
                  <thead>
                  <tr>
                  <td >
                  <cfoutput query="attachment">
                  #description#
                  </td>
                  <td align="center">
                  <a href="attachments/#path#" target="_blank" >view</a>
                  <br>
                  </td>
                  <td>
                  
                  <cfif form.confirmed EQ 1>
                  <cfquery name="deleteattachment" datasource="CustomerSupport">
                           DELETE 
                           FROM dbo.tbl_CS_attachments
                           WHERE fk_ticketID = #URL.pk_ticketID#
                  </cfquery>
                  <cflock timeout="60">
                  <cffile action="delete" 
                  file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
                  </cflock>
                  </cfif>
                  <input type="hidden" name="confirmed" value="1">
                  <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
                  <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
                  
                  </td>
                  <td>
                  
                  </td></cfoutput>
                  
                  </tr>
                  </table>
                  </form>
                  Thank you,
                  Rach

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Yes, exactly. How you have it now, it would display the attachments and then delete the attachment(s) that need to be deleted, so it'll always be one step behind.

                    Comment

                    • bonneylake
                      Contributor
                      • Aug 2008
                      • 769

                      #11
                      Originally posted by acoder
                      Yes, exactly. How you have it now, it would display the attachments and then delete the attachment(s) that need to be deleted, so it'll always be one step behind.
                      Hey Acoder,

                      Here is how i did it but now it looks kinda funny because it puts the delete above the filename an kinda wanted it to show it like this

                      file name | view| Delete

                      and its showing it like

                      delete
                      file name|view|

                      Did i need to just move the delete query or the cflock along with it? here is what i have.
                      Code:
                      <table style="100%" class="ticketlist">
                      <col style="width:10%;" />
                      <col style="width:3%;" />
                      <col style="width:3%;" />
                      <thead>
                      <tr class="attachment" >
                      <th>Attachment</th>
                      <th>View</th>
                      <th>Download</th>
                      </tr>
                      <thead>
                      <tr>
                      <td >
                      <cfif form.confirmed EQ 1>
                      <cfquery name="deleteattachment" datasource="CustomerSupport">
                               DELETE 
                               FROM dbo.tbl_CS_attachments
                               WHERE fk_ticketID = #URL.pk_ticketID#
                      </cfquery>
                      <cflock timeout="60">
                      <cffile action="delete" 
                      file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
                      </cflock>
                      </cfif>
                      <cfoutput query="attachment">
                      #description#
                      </td>
                      <td align="center">
                      <a href="attachments/#path#" target="_blank" >view</a>
                      <br>
                      </td>
                      <td>
                      </td>
                      
                      
                      <input type="hidden" name="confirmed" value="1">
                      <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
                      <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
                      
                      </td>
                      <td>
                      
                      </td></cfoutput>
                      
                      </tr>
                      </table>
                      </form>
                      Also, when i clicked delete it had an issue becuase it was not wrapped around the cfoutput query="attachme nt" it brought up the error

                      An error occurred while evaluating the expression:


                      "C:\Inetpub\Dev elopment\WWWRoo t\RachelB\footp rints\form\atta chments\#path#"


                      Error resolving parameter PATH


                      ColdFusion was unable to determine the value of the parameter.

                      Thank you,
                      Rach

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        The delete query/lock code should be outside this table, probably near the top of the page.

                        I notice you have a stray </td> which is probably causing the alignment problems.

                        Comment

                        • bonneylake
                          Contributor
                          • Aug 2008
                          • 769

                          #13
                          Originally posted by acoder
                          The delete query/lock code should be outside this table, probably near the top of the page.

                          I notice you have a stray </td> which is probably causing the alignment problems.
                          Hey Acoder,

                          When i moved it to the top i got the same error. It basically wants it between the <cfoutput query="attachme nt">. But here is what i have.

                          Code:
                          <html>
                          <head>
                          <title>Prevoiusly Submitted Attachments</title>
                          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                          
                          	</style>
                              <cfparam name="form.confirmed" default="0">
                              
                          <cfquery name="attachment" datasource="CustomerSupport">
                                   SELECT fk_ticketID,description,path
                                   FROM dbo.tbl_CS_attachments
                                   WHERE fk_ticketID = #URL.pk_ticketID#
                          </cfquery>
                          
                          
                          <cfquery name="ticket" datasource="CustomerSupport">
                          		SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
                                  FROM        
                                  dbo.tbl_CS_ticketMaster
                                  WHERE pk_ticketID = #URL.pk_ticketID#
                          </cfquery>
                          
                          <cfquery name="deleteattachment" datasource="CustomerSupport">
                                   DELETE 
                                   FROM dbo.tbl_CS_attachments
                                   WHERE fk_ticketID = #URL.pk_ticketID#
                          </cfquery>
                          <cflock timeout="60">
                          <cffile action="delete" 
                          file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
                          </cflock>
                          
                          <script>
                          function confirmDelete(delUrl) {
                            if (confirm("Are you sure you want to delete")) {
                              document.location = delUrl;
                            }
                          }
                          </script>
                          </head>
                          <body>
                          <form method="post">
                          <cfoutput query="ticket">
                          <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
                          </cfoutput>
                          <cfoutput query="attachment">
                          <input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
                          </cfoutput>
                          <table class="title">
                          <thead>
                          <tr>
                          <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
                          </th>
                          </tr>
                          </thead>
                          </table>
                          
                          <table style="100%" class="ticketlist">
                          <col style="width:10%;" />
                          <col style="width:3%;" />
                          <col style="width:3%;" />
                          <thead>
                          <tr class="attachment" >
                          <th>Attachment</th>
                          <th>View</th>
                          <th>Download</th>
                          </tr>
                          <thead>
                          <tr>
                          <td >
                          
                          <cfoutput query="attachment">
                          #description#
                          <cfif form.confirmed EQ 1>
                          
                          </cfif>
                          </td>
                          <td align="center">
                          <a href="attachments/#path#" target="_blank" >view</a>
                          <br>
                          </td>
                          <td>
                          
                          
                          <input type="hidden" name="confirmed" value="1">
                          <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
                          <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
                          
                          </td>
                          <td>
                          
                          </td></cfoutput>
                          
                          </tr>
                          </table>
                          </form>
                          
                          </body>
                          </html>
                          Thank you,
                          Rach

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            You had to move the cfif tags as well. You don't want to delete unless the delete button's been clicked.

                            Comment

                            • bonneylake
                              Contributor
                              • Aug 2008
                              • 769

                              #15
                              Originally posted by acoder
                              You had to move the cfif tags as well. You don't want to delete unless the delete button's been clicked.
                              Hey Acoder,

                              it is giving me the following error

                              Error resolving parameter PATH


                              ColdFusion was unable to determine the value of the parameter

                              an this is the line its having trouble with
                              Code:
                              <cffile action="delete" 
                              file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
                              here is what i have in full

                              Code:
                              <html>
                              <head>
                              <title>Prevoiusly Submitted Attachments</title>
                              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                                  <cfparam name="form.confirmed" default="0">
                                  
                              <cfquery name="attachment" datasource="CustomerSupport">
                                       SELECT fk_ticketID,description,path
                                       FROM dbo.tbl_CS_attachments
                                       WHERE fk_ticketID = #URL.pk_ticketID#
                              </cfquery>
                              
                              
                              <cfquery name="ticket" datasource="CustomerSupport">
                              		SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
                                      FROM        
                                      dbo.tbl_CS_ticketMaster
                                      WHERE pk_ticketID = #URL.pk_ticketID#
                              </cfquery>
                              
                              <cfquery name="deleteattachment" datasource="CustomerSupport">
                                       DELETE 
                                       FROM dbo.tbl_CS_attachments
                                       WHERE fk_ticketID = #URL.pk_ticketID#
                              </cfquery>
                              
                              <cfif form.confirmed EQ 1>
                              <cflock timeout="60">
                              <cffile action="delete" 
                              file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
                              </cflock>
                              </cfif>
                              
                              <script>
                              function confirmDelete(delUrl) {
                                if (confirm("Are you sure you want to delete")) {
                                  document.location = delUrl;
                                }
                              }
                              </script>
                              </head>
                              <body>
                              <form method="post">
                              <cfoutput query="ticket">
                              <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
                              </cfoutput>
                              <cfoutput query="attachment">
                              <input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
                              </cfoutput>
                              <table class="title">
                              <thead>
                              <tr>
                              <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
                              </th>
                              </tr>
                              </thead>
                              </table>
                              
                              <table style="100%" class="ticketlist">
                              <col style="width:10%;" />
                              <col style="width:3%;" />
                              <col style="width:3%;" />
                              <thead>
                              <tr class="attachment" >
                              <th>Attachment</th>
                              <th>View</th>
                              <th>Download</th>
                              </tr>
                              <thead>
                              <tr>
                              <td >
                              
                              <cfoutput query="attachment">
                              #description#
                              
                              
                              
                              </td>
                              <td align="center">
                              <a href="attachments/#path#" target="_blank" >view</a>
                              <br>
                              </td>
                              <td>
                              
                              
                              <input type="hidden" name="confirmed" value="1">
                              <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
                              <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
                              
                              </td>
                              <td>
                              
                              </td></cfoutput>
                              
                              </tr>
                              </table>
                              </form>
                              
                              </body>
                              </html>
                              Thank you,
                              Rach

                              Comment

                              Working...