Connecting Tech Pros Worldwide Forums | Help | Site Map

How to delete and download attachments?

Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#1: Oct 17 '08
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.

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2.  
  3. <cfquery name="attachment" datasource="CustomerSupport">
  4.          SELECT fk_ticketID,description,path
  5.          FROM dbo.tbl_CS_attachments
  6.          WHERE fk_ticketID = #URL.pk_ticketID#
  7. </cfquery>
  8.  
  9.  
  10. <form method="post">
  11. <cfoutput query="ticket">
  12. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  13. </cfoutput>
  14. <cfoutput query="attachment">
  15. <input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
  16. </cfoutput>
  17.  
  18. <cfoutput query="attachment">
  19. #description#
  20. <a href="attachments/#path#" target="_blank" >view</a>
  21. <br>
  22. <cfif form.confirmed EQ 1>
  23. <cflock timeout="60">
  24. <cffile action="delete" 
  25. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  26. </cflock>
  27. </cfif>
  28. <input type="hidden" name="confirmed" value="1">
  29. <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
  30. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  31. </cfoutput>
  32. </form>
Thank you,
Rach

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Oct 17 '08

re: How to delete and download attachments?


We'll deal with one thing at a time. Deleting first. Where's the delete query?
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#3: Oct 17 '08

re: How to delete and download attachments?


Quote:

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

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="deleteattachment" datasource="CustomerSupport">
  2.          DELETE 
  3.          FROM dbo.tbl_CS_attachments
  4.          WHERE fk_ticketID = #URL.pk_ticketID#
  5. </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.

Expand|Select|Wrap|Line Numbers
  1. <cflock timeout="60">
  2. <cffile action="copy" 
  3. source="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" destination="">
  4. </cflock>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Oct 17 '08

re: How to delete and download attachments?


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.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#5: Oct 17 '08

re: How to delete and download attachments?


Quote:

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?

Expand|Select|Wrap|Line Numbers
  1. <cfif form.confirmed EQ 1>
  2.  
  3. <cflock timeout="60">
  4. <cffile action="delete" 
  5.  
  6. <cfquery name="deleteattachment" datasource="CustomerSupport">
  7.          DELETE 
  8.          FROM dbo.tbl_CS_attachments
  9.          WHERE fk_ticketID = #URL.pk_ticketID#
  10. </cfquery>
  11. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  12. </cflock>
  13. </cfif>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Oct 17 '08

re: How to delete and download attachments?


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.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#7: Oct 17 '08

re: How to delete and download attachments?


Quote:

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?

Expand|Select|Wrap|Line Numbers
  1. <cfcontent 
  2. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  3. 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
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#8: Oct 20 '08

re: How to delete and download attachments?


Put the delete query first before running any queries showing the attachments.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#9: Oct 20 '08

re: How to delete and download attachments?


Quote:

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.

Expand|Select|Wrap|Line Numbers
  1. <form method="post">
  2. <table style="100%" class="ticketlist">
  3. <col style="width:10%;" />
  4. <col style="width:3%;" />
  5. <col style="width:3%;" />
  6. <thead>
  7. <tr class="attachment" >
  8. <th>Attachment</th>
  9. <th>View</th>
  10. <th>Download</th>
  11. </tr>
  12. <thead>
  13. <tr>
  14. <td >
  15. <cfoutput query="attachment">
  16. #description#
  17. </td>
  18. <td align="center">
  19. <a href="attachments/#path#" target="_blank" >view</a>
  20. <br>
  21. </td>
  22. <td>
  23.  
  24. <cfif form.confirmed EQ 1>
  25. <cfquery name="deleteattachment" datasource="CustomerSupport">
  26.          DELETE 
  27.          FROM dbo.tbl_CS_attachments
  28.          WHERE fk_ticketID = #URL.pk_ticketID#
  29. </cfquery>
  30. <cflock timeout="60">
  31. <cffile action="delete" 
  32. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  33. </cflock>
  34. </cfif>
  35. <input type="hidden" name="confirmed" value="1">
  36. <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
  37. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  38.  
  39. </td>
  40. <td>
  41.  
  42. </td></cfoutput>
  43.  
  44. </tr>
  45. </table>
  46. </form>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#10: Oct 20 '08

re: How to delete and download attachments?


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.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#11: Oct 20 '08

re: How to delete and download attachments?


Quote:

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.
Expand|Select|Wrap|Line Numbers
  1. <table style="100%" class="ticketlist">
  2. <col style="width:10%;" />
  3. <col style="width:3%;" />
  4. <col style="width:3%;" />
  5. <thead>
  6. <tr class="attachment" >
  7. <th>Attachment</th>
  8. <th>View</th>
  9. <th>Download</th>
  10. </tr>
  11. <thead>
  12. <tr>
  13. <td >
  14. <cfif form.confirmed EQ 1>
  15. <cfquery name="deleteattachment" datasource="CustomerSupport">
  16.          DELETE 
  17.          FROM dbo.tbl_CS_attachments
  18.          WHERE fk_ticketID = #URL.pk_ticketID#
  19. </cfquery>
  20. <cflock timeout="60">
  21. <cffile action="delete" 
  22. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  23. </cflock>
  24. </cfif>
  25. <cfoutput query="attachment">
  26. #description#
  27. </td>
  28. <td align="center">
  29. <a href="attachments/#path#" target="_blank" >view</a>
  30. <br>
  31. </td>
  32. <td>
  33. </td>
  34.  
  35.  
  36. <input type="hidden" name="confirmed" value="1">
  37. <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
  38. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  39.  
  40. </td>
  41. <td>
  42.  
  43. </td></cfoutput>
  44.  
  45. </tr>
  46. </table>
  47. </form>
Also, when i clicked delete it had an issue becuase it was not wrapped around the cfoutput query="attachment" it brought up the error

An error occurred while evaluating the expression:


"C:\Inetpub\Development\WWWRoot\RachelB\footprints \form\attachments\#path#"


Error resolving parameter PATH


ColdFusion was unable to determine the value of the parameter.

Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#12: Oct 20 '08

re: How to delete and download attachments?


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.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#13: Oct 20 '08

re: How to delete and download attachments?


Quote:

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="attachment">. But here is what i have.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Prevoiusly Submitted Attachments</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5.  
  6.     </style>
  7.     <cfparam name="form.confirmed" default="0">
  8.  
  9. <cfquery name="attachment" datasource="CustomerSupport">
  10.          SELECT fk_ticketID,description,path
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE fk_ticketID = #URL.pk_ticketID#
  13. </cfquery>
  14.  
  15.  
  16. <cfquery name="ticket" datasource="CustomerSupport">
  17.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  18.         FROM        
  19.         dbo.tbl_CS_ticketMaster
  20.         WHERE pk_ticketID = #URL.pk_ticketID#
  21. </cfquery>
  22.  
  23. <cfquery name="deleteattachment" datasource="CustomerSupport">
  24.          DELETE 
  25.          FROM dbo.tbl_CS_attachments
  26.          WHERE fk_ticketID = #URL.pk_ticketID#
  27. </cfquery>
  28. <cflock timeout="60">
  29. <cffile action="delete" 
  30. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  31. </cflock>
  32.  
  33. <script>
  34. function confirmDelete(delUrl) {
  35.   if (confirm("Are you sure you want to delete")) {
  36.     document.location = delUrl;
  37.   }
  38. }
  39. </script>
  40. </head>
  41. <body>
  42. <form method="post">
  43. <cfoutput query="ticket">
  44. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  45. </cfoutput>
  46. <cfoutput query="attachment">
  47. <input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
  48. </cfoutput>
  49. <table class="title">
  50. <thead>
  51. <tr>
  52. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  53. </th>
  54. </tr>
  55. </thead>
  56. </table>
  57.  
  58. <table style="100%" class="ticketlist">
  59. <col style="width:10%;" />
  60. <col style="width:3%;" />
  61. <col style="width:3%;" />
  62. <thead>
  63. <tr class="attachment" >
  64. <th>Attachment</th>
  65. <th>View</th>
  66. <th>Download</th>
  67. </tr>
  68. <thead>
  69. <tr>
  70. <td >
  71.  
  72. <cfoutput query="attachment">
  73. #description#
  74. <cfif form.confirmed EQ 1>
  75.  
  76. </cfif>
  77. </td>
  78. <td align="center">
  79. <a href="attachments/#path#" target="_blank" >view</a>
  80. <br>
  81. </td>
  82. <td>
  83.  
  84.  
  85. <input type="hidden" name="confirmed" value="1">
  86. <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
  87. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  88.  
  89. </td>
  90. <td>
  91.  
  92. </td></cfoutput>
  93.  
  94. </tr>
  95. </table>
  96. </form>
  97.  
  98. </body>
  99. </html>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#14: Oct 20 '08

re: How to delete and download attachments?


You had to move the cfif tags as well. You don't want to delete unless the delete button's been clicked.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#15: Oct 20 '08

re: How to delete and download attachments?


Quote:

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
Expand|Select|Wrap|Line Numbers
  1. <cffile action="delete" 
  2. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
here is what i have in full

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Prevoiusly Submitted Attachments</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5.     <cfparam name="form.confirmed" default="0">
  6.  
  7. <cfquery name="attachment" datasource="CustomerSupport">
  8.          SELECT fk_ticketID,description,path
  9.          FROM dbo.tbl_CS_attachments
  10.          WHERE fk_ticketID = #URL.pk_ticketID#
  11. </cfquery>
  12.  
  13.  
  14. <cfquery name="ticket" datasource="CustomerSupport">
  15.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  16.         FROM        
  17.         dbo.tbl_CS_ticketMaster
  18.         WHERE pk_ticketID = #URL.pk_ticketID#
  19. </cfquery>
  20.  
  21. <cfquery name="deleteattachment" datasource="CustomerSupport">
  22.          DELETE 
  23.          FROM dbo.tbl_CS_attachments
  24.          WHERE fk_ticketID = #URL.pk_ticketID#
  25. </cfquery>
  26.  
  27. <cfif form.confirmed EQ 1>
  28. <cflock timeout="60">
  29. <cffile action="delete" 
  30. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  31. </cflock>
  32. </cfif>
  33.  
  34. <script>
  35. function confirmDelete(delUrl) {
  36.   if (confirm("Are you sure you want to delete")) {
  37.     document.location = delUrl;
  38.   }
  39. }
  40. </script>
  41. </head>
  42. <body>
  43. <form method="post">
  44. <cfoutput query="ticket">
  45. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  46. </cfoutput>
  47. <cfoutput query="attachment">
  48. <input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
  49. </cfoutput>
  50. <table class="title">
  51. <thead>
  52. <tr>
  53. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  54. </th>
  55. </tr>
  56. </thead>
  57. </table>
  58.  
  59. <table style="100%" class="ticketlist">
  60. <col style="width:10%;" />
  61. <col style="width:3%;" />
  62. <col style="width:3%;" />
  63. <thead>
  64. <tr class="attachment" >
  65. <th>Attachment</th>
  66. <th>View</th>
  67. <th>Download</th>
  68. </tr>
  69. <thead>
  70. <tr>
  71. <td >
  72.  
  73. <cfoutput query="attachment">
  74. #description#
  75.  
  76.  
  77.  
  78. </td>
  79. <td align="center">
  80. <a href="attachments/#path#" target="_blank" >view</a>
  81. <br>
  82. </td>
  83. <td>
  84.  
  85.  
  86. <input type="hidden" name="confirmed" value="1">
  87. <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
  88. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  89.  
  90. </td>
  91. <td>
  92.  
  93. </td></cfoutput>
  94.  
  95. </tr>
  96. </table>
  97. </form>
  98.  
  99. </body>
  100. </html>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#16: Oct 20 '08

re: How to delete and download attachments?


The delete query also needs to go inside the confirmed check.

The path is from the attachment query. It'd be a good idea to get only the required path for the file to be deleted from the attachment query using a query of queries, though you could use a normal query too.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#17: Oct 20 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

The delete query also needs to go inside the confirmed check.

The path is from the attachment query. It'd be a good idea to get only the required path for the file to be deleted from the attachment query using a query of queries, though you could use a normal query too.

Hey Acoder,

Would something like this work?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Prevoiusly Submitted Attachments</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5.  
  6.  
  7.     <cfparam name="form.confirmed" default="0">
  8.  
  9. <cfquery name="attachment" datasource="CustomerSupport">
  10.          SELECT fk_ticketID,description,path
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE fk_ticketID = #URL.pk_ticketID#
  13. </cfquery>
  14.  
  15.  
  16. <cfquery name="ticket" datasource="CustomerSupport">
  17.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  18.         FROM        
  19.         dbo.tbl_CS_ticketMaster
  20.         WHERE pk_ticketID = #URL.pk_ticketID#
  21. </cfquery>
  22.  
  23. <cfquery name="getattachment" dbtype="query" >
  24. SELECT *
  25. FROM attachment
  26. WHERE path=<cfqueryparam value="#path#" 
  27. cfsqltype="cf_sql_char" maxLength="20">
  28. </cfquery>
  29.  
  30. <cfif form.confirmed EQ 1>
  31. <cfquery name="deleteattachment" datasource="CustomerSupport">
  32.          DELETE 
  33.          FROM dbo.tbl_CS_attachments
  34.          WHERE fk_ticketID = #URL.pk_ticketID#
  35. </cfquery>
  36. <cflock timeout="60">
  37. <cffile action="delete" 
  38. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  39. </cflock>
  40. </cfif>
  41.  
  42. <script>
  43. function confirmDelete(delUrl) {
  44.   if (confirm("Are you sure you want to delete")) {
  45.     document.location = delUrl;
  46.   }
  47. }
  48. </script>
  49. </head>
  50. <body>
  51. <form method="post">
  52. <cfoutput query="ticket">
  53. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  54. </cfoutput>
  55. <cfoutput query="attachment">
  56. <input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
  57. </cfoutput>
  58. <table class="title">
  59. <thead>
  60. <tr>
  61. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  62. </th>
  63. </tr>
  64. </thead>
  65. </table>
  66.  
  67. <table style="100%" class="ticketlist">
  68. <col style="width:10%;" />
  69. <col style="width:3%;" />
  70. <col style="width:3%;" />
  71. <thead>
  72. <tr class="attachment" >
  73. <th>Attachment</th>
  74. <th>View</th>
  75. <th>Download</th>
  76. </tr>
  77. <thead>
  78. <tr>
  79. <td >
  80.  
  81. <cfoutput query="attachment">
  82. #description#
  83.  
  84.  
  85.  
  86. </td>
  87. <td align="center">
  88. <a href="attachments/#path#" target="_blank" >view</a>
  89. <br>
  90. </td>
  91. <td>
  92.  
  93.  
  94. <input type="hidden" name="confirmed" value="1">
  95. <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
  96. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  97.  
  98. </td>
  99. <td>
  100.  
  101. </td></cfoutput>
  102.  
  103. </tr>
  104. </table>
  105. </form>
  106.  
  107. </body>
  108. </html>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#18: Oct 20 '08

re: How to delete and download attachments?


Comparing to path wouldn't make sense because you don't know it. Try the ticket id field instead.

Just a quick question: is this supposed to delete only one attachment at a time?
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#19: Oct 20 '08

re: How to delete and download attachments?


Hey Acoder,

Yes this is suppose to delete only one attachment at a time. An ok so is this correct?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Prevoiusly Submitted Attachments</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5.  
  6.     <cfparam name="form.confirmed" default="0">
  7.  
  8. <cfquery name="attachment" datasource="CustomerSupport">
  9.          SELECT fk_ticketID,description,path
  10.          FROM dbo.tbl_CS_attachments
  11.          WHERE fk_ticketID = #URL.pk_ticketID#
  12. </cfquery>
  13.  
  14.  
  15. <cfquery name="ticket" datasource="CustomerSupport">
  16.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  17.         FROM        
  18.         dbo.tbl_CS_ticketMaster
  19.         WHERE pk_ticketID = #URL.pk_ticketID#
  20. </cfquery>
  21.  
  22. <cfquery name="getattachment" dbtype="query" >
  23. SELECT *
  24. FROM attachment
  25. WHERE fk_ticketID=<cfqueryparam value="#path#" 
  26. cfsqltype="cf_sql_char" maxLength="20">
  27. </cfquery>
  28.  
  29. <cfif form.confirmed EQ 1>
  30. <cfquery name="deleteattachment" datasource="CustomerSupport">
  31.          DELETE 
  32.          FROM dbo.tbl_CS_attachments
  33.          WHERE fk_ticketID = #URL.pk_ticketID#
  34. </cfquery>
  35. <cflock timeout="60">
  36. <cffile action="delete" 
  37. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  38. </cflock>
  39. </cfif>
  40.  
  41. <script>
  42. function confirmDelete(delUrl) {
  43.   if (confirm("Are you sure you want to delete")) {
  44.     document.location = delUrl;
  45.   }
  46. }
  47. </script>
  48. </head>
  49. <body>
  50. <form method="post">
  51. <cfoutput query="ticket">
  52. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  53. </cfoutput>
  54. <cfoutput query="attachment">
  55. <input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
  56. </cfoutput>
  57. <table class="title">
  58. <thead>
  59. <tr>
  60. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  61. </th>
  62. </tr>
  63. </thead>
  64. </table>
  65.  
  66. <table style="100%" class="ticketlist">
  67. <col style="width:10%;" />
  68. <col style="width:3%;" />
  69. <col style="width:3%;" />
  70. <thead>
  71. <tr class="attachment" >
  72. <th>Attachment</th>
  73. <th>View</th>
  74. <th>Download</th>
  75. </tr>
  76. <thead>
  77. <tr>
  78. <td >
  79.  
  80. <cfoutput query="attachment">
  81. #description#
  82.  
  83.  
  84.  
  85. </td>
  86. <td align="center">
  87. <a href="attachments/#path#" target="_blank" >view</a>
  88. <br>
  89. </td>
  90. <td>
  91.  
  92.  
  93. <input type="hidden" name="confirmed" value="1">
  94. <input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
  95. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  96.  
  97. </td>
  98. <td>
  99.  
  100. </td></cfoutput>
  101.  
  102. </tr>
  103. </table>
  104. </form>
  105.  
  106. </body>
  107. </html>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#20: Oct 20 '08

re: How to delete and download attachments?


Is fk_ticketID the primary key of the attachment table?
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#21: Oct 20 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

Is fk_ticketID the primary key of the attachment table?

Hey Acoder,

Actually my primary key is pk_attachID.But i don't use it anywhere because it just makes is so that i can delete attachments. Basically just counts.

Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#22: Oct 20 '08

re: How to delete and download attachments?


The reason I ask is that currently the delete query would delete all attachments with that ticket ID whereas you only want to delete the one whose delete button has been clicked. To do that, uniquely identify it using the primary key in the display (hidden variable) and then use that in the delete query to get the path/attachment.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#23: Oct 20 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

The reason I ask is that currently the delete query would delete all attachments with that ticket ID whereas you only want to delete the one whose delete button has been clicked. To do that, uniquely identify it using the primary key in the display (hidden variable) and then use that in the delete query to get the path/attachment.

Hey Acoder,

So would this work?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Prevoiusly Submitted Attachments</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5.  
  6.  
  7.     <cfparam name="form.confirmed" default="0">
  8.  
  9. <cfquery name="attachment" datasource="CustomerSupport">
  10.          SELECT fk_ticketID,description,path
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE fk_ticketID = #URL.pk_ticketID#
  13. </cfquery>
  14.  
  15.  
  16. <cfquery name="ticket" datasource="CustomerSupport">
  17.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  18.         FROM        
  19.         dbo.tbl_CS_ticketMaster
  20.         WHERE pk_ticketID = #URL.pk_ticketID#
  21. </cfquery>
  22.  
  23. <cfquery name="getattachment" dbtype="query" >
  24. SELECT *
  25. FROM attachment
  26. WHERE fk_ticketID=<cfqueryparam value="#path#" 
  27. cfsqltype="cf_sql_char" maxLength="20">
  28. </cfquery>
  29.  
  30. <cfif form.confirmed EQ 1>
  31. <cfquery name="deleteattachment" datasource="CustomerSupport">
  32.          DELETE 
  33.          FROM dbo.tbl_CS_attachments
  34.          WHERE pk_attachID = #URL.pk_ticketID#
  35. </cfquery>
  36. <cflock timeout="60">
  37. <cffile action="delete" 
  38. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  39. </cflock>
  40. </cfif>
  41.  
  42. <script>
  43. function confirmDelete(delUrl) {
  44.   if (confirm("Are you sure you want to delete")) {
  45.     document.location = delUrl;
  46.   }
  47. }
  48. </script>
  49. </head>
  50. <body>
  51. <form method="post">
  52. <cfoutput query="ticket">
  53. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  54. </cfoutput>
  55. <cfoutput query="attachment">
  56. <input type="hidden" name="pk_attachID" id="pk_attachID" value="#pk_attachID#" />
  57. </cfoutput>
  58. <table class="title">
  59. <thead>
  60. <tr>
  61. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  62. </th>
  63. </tr>
  64. </thead>
  65. </table>
  66.  
  67. <table style="100%" class="ticketlist">
  68. <col style="width:10%;" />
  69. <col style="width:3%;" />
  70. <col style="width:3%;" />
  71. <thead>
  72. <tr class="attachment" >
  73. <th>Attachment</th>
  74. <th>View</th>
  75. <th>Download</th>
  76. </tr>
  77. <thead>
  78. <tr>
  79. <td >
  80.  
  81. <cfoutput query="attachment">
  82. #description#
  83.  
  84.  
  85.  
  86. </td>
  87. <td align="center">
  88. <a href="attachments/#path#" target="_blank" >view</a>
  89. <br>
  90. </td>
  91. <td>
  92.  
  93.  
  94. <input type="hidden" name="confirmed" value="1">
  95. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  96. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  97.  
  98. </td>
  99. <td>
  100.  
  101. </td></cfoutput>
  102.  
  103. </tr>
  104. </table>
  105. </form>
  106.  
  107. </body>
  108. </html>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#24: Oct 20 '08

re: How to delete and download attachments?


Not quite. The cfqueryparam value should be the attachID and the field compared again should be pk_attachID. For this to work, this field should also be included in the attachment query.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#25: Oct 20 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

Not quite. The cfqueryparam value should be the attachID and the field compared again should be pk_attachID. For this to work, this field should also be included in the attachment query.

Hey Acoder,

Would this be correct?

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2.  
  3. <cfquery name="ticket" datasource="CustomerSupport">
  4.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  5.         FROM        
  6.         dbo.tbl_CS_ticketMaster
  7.         WHERE pk_ticketID = #URL.pk_ticketID#
  8. </cfquery>
  9.  
  10. <cfquery name="attachment" datasource="CustomerSupport">
  11.          SELECT pk_attachID,fk_ticketID,description,path
  12.          FROM dbo.tbl_CS_attachments
  13.          WHERE fk_ticketID = #URL.pk_ticketID#
  14. </cfquery>
  15.  
  16. <cfquery name="getattachment" dbtype="query" >
  17. SELECT *
  18. FROM attachment
  19. WHERE pk_attachID=<cfqueryparam value="#attachID#" 
  20. cfsqltype="cf_sql_char" maxLength="20">
  21. </cfquery>
  22.  
  23. <cfif form.confirmed EQ 1>
  24. <cfquery name="deleteattachment" datasource="CustomerSupport">
  25.          DELETE 
  26.          FROM dbo.tbl_CS_attachments
  27.          WHERE pk_attachID = #URL.pk_ticketID#
  28. </cfquery>
  29. <cflock timeout="60">
  30. <cffile action="delete" 
  31. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  32. </cflock>
  33. </cfif>
  34.  
  35. <script>
  36. function confirmDelete(delUrl) {
  37.   if (confirm("Are you sure you want to delete")) {
  38.     document.location = delUrl;
  39.   }
  40. }
  41. </script>
  42. </head>
  43. <body>
  44. <form method="post">
  45. <cfoutput query="ticket">
  46. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  47. </cfoutput>
  48. <cfoutput query="attachment">
  49. <input type="hidden" name="pk_attachID" id="pk_attachID" value="#pk_attachID#" />
  50. </cfoutput>
  51. <table class="title">
  52. <thead>
  53. <tr>
  54. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  55. </th>
  56. </tr>
  57. </thead>
  58. </table>
  59.  
  60. <table style="100%" class="ticketlist">
  61. <col style="width:10%;" />
  62. <col style="width:3%;" />
  63. <col style="width:3%;" />
  64. <thead>
  65. <tr class="attachment" >
  66. <th>Attachment</th>
  67. <th>View</th>
  68. <th>Download</th>
  69. </tr>
  70. <thead>
  71. <tr>
  72. <td >
  73.  
  74. <cfoutput query="attachment">
  75. #description#
  76.  
  77.  
  78.  
  79. </td>
  80. <td align="center">
  81. <a href="attachments/#path#" target="_blank" >view</a>
  82. <br>
  83. </td>
  84. <td>
  85.  
  86.  
  87. <input type="hidden" name="confirmed" value="1">
  88. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  89. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  90.  
  91. </td>
  92. <td>
  93. <!---<cfcontent 
  94. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  95. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  96. deleteFile = "no">--->
  97. </td></cfoutput>
  98.  
  99. </tr>
  100. </table>
  101. </form>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#26: Oct 20 '08

re: How to delete and download attachments?


#attachID# should be the hidden field value passed from the client-side. I would also say that the "getattachment" query should be in the confirmed check cfif.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#27: Oct 20 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

#attachID# should be the hidden field value passed from the client-side. I would also say that the "getattachment" query should be in the confirmed check cfif.

Hey Acoder,

Here is what i have, an its giving me a site administrator error. An i know that means it don't like what i am doing any ideas? it was giving me errors just fine till i moved getattachment under cfif form.confirmed

Expand|Select|Wrap|Line Numbers
  1.   <cfparam name="form.confirmed" default="0">
  2.  
  3.  
  4.  
  5. <cfquery name="ticket" datasource="CustomerSupport">
  6.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  7.         FROM        
  8.         dbo.tbl_CS_ticketMaster
  9.         WHERE pk_ticketID = #URL.pk_ticketID#
  10. </cfquery>
  11.  
  12. <cfquery name="attachment" datasource="CustomerSupport">
  13.          SELECT pk_attachID,fk_ticketID,description,path
  14.          FROM dbo.tbl_CS_attachments
  15.          WHERE fk_ticketID = #URL.pk_ticketID#
  16. </cfquery>
  17.  
  18.  
  19.  
  20. <cfif form.confirmed EQ 1>
  21.  
  22. <cfquery name="getattachment" dbtype="query" >
  23. SELECT *
  24. FROM attachment
  25. WHERE pk_attachID=<cfqueryparam value="#attachID#" 
  26. cfsqltype="cf_sql_char" maxLength="20">
  27. </cfquery>
  28.  
  29. <cfquery name="deleteattachment" datasource="CustomerSupport">
  30.          DELETE 
  31.          FROM dbo.tbl_CS_attachments
  32.          WHERE pk_attachID = #URL.pk_ticketID#
  33. </cfquery>
  34. <cflock timeout="60">
  35. <cffile action="delete" 
  36. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  37. </cflock>
  38. </cfif>
  39.  
  40. <script>
  41. function confirmDelete(delUrl) {
  42.   if (confirm("Are you sure you want to delete")) {
  43.     document.location = delUrl;
  44.   }
  45. }
  46. </script>
  47. </head>
  48. <body>
  49. <form method="post">
  50. <cfoutput query="ticket">
  51. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  52. </cfoutput>
  53. <cfoutput query="attachment">
  54. <input type="hidden" name="attachID" id="attachID" value="#attachID#" />
  55. </cfoutput>
  56. <table class="title">
  57. <thead>
  58. <tr>
  59. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  60. </th>
  61. </tr>
  62. </thead>
  63. </table>
  64.  
  65. <table style="100%" class="ticketlist">
  66. <col style="width:10%;" />
  67. <col style="width:3%;" />
  68. <col style="width:3%;" />
  69. <thead>
  70. <tr class="attachment" >
  71. <th>Attachment</th>
  72. <th>View</th>
  73. <th>Download</th>
  74. </tr>
  75. <thead>
  76. <tr>
  77. <td >
  78.  
  79. <cfoutput query="attachment">
  80. #description#
  81.  
  82.  
  83.  
  84. </td>
  85. <td align="center">
  86. <a href="attachments/#path#" target="_blank" >view</a>
  87. <br>
  88. </td>
  89. <td>
  90.  
  91.  
  92. <input type="hidden" name="confirmed" value="1">
  93. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  94. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  95.  
  96. </td>
  97. <td>
  98. <!---<cfcontent 
  99. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  100. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  101. deleteFile = "no">--->
  102. </td></cfoutput>
  103.  
  104. </tr>
  105. </table>
  106. </form>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#28: Oct 21 '08

re: How to delete and download attachments?


I think #attachID# should probably be #form.pk_attachID#. Is the attachment ID stored as a string in the database or is it an integer? If an integer, you need to change the cfsqltype attribute of the cfqueryparam.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#29: Oct 21 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

I think #attachID# should probably be #form.pk_attachID#. Is the attachment ID stored as a string in the database or is it an integer? If an integer, you need to change the cfsqltype attribute of the cfqueryparam.

Hey Acoder,

Well the field is numeric so do i need to change it still? an ok here is what i have now.
Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2.  
  3.  
  4.  
  5. <cfquery name="ticket" datasource="CustomerSupport">
  6.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  7.         FROM        
  8.         dbo.tbl_CS_ticketMaster
  9.         WHERE pk_ticketID = #URL.pk_ticketID#
  10. </cfquery>
  11.  
  12. <cfquery name="attachment" datasource="CustomerSupport">
  13.          SELECT pk_attachID,fk_ticketID,description,path
  14.          FROM dbo.tbl_CS_attachments
  15.          WHERE fk_ticketID = #URL.pk_ticketID#
  16. </cfquery>
  17.  
  18.  
  19.  
  20. <cfif form.confirmed EQ 1>
  21.  
  22. <cfquery name="getattachment" dbtype="query" >
  23. SELECT *
  24. FROM attachment
  25. WHERE pk_attachID=<cfqueryparam value="#form.attachID#" 
  26. cfsqltype="cf_sql_char" maxLength="20">
  27. </cfquery>
  28.  
  29. <cfquery name="deleteattachment" datasource="CustomerSupport">
  30.          DELETE 
  31.          FROM dbo.tbl_CS_attachments
  32.          WHERE pk_attachID = #URL.pk_ticketID#
  33. </cfquery>
  34. <cflock timeout="60">
  35. <cffile action="delete" 
  36. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  37. </cflock>
  38. </cfif>
  39.  
  40. <script>
  41. function confirmDelete(delUrl) {
  42.   if (confirm("Are you sure you want to delete")) {
  43.     document.location = delUrl;
  44.   }
  45. }
  46. </script>
  47. </head>
  48. <body>
  49. <form method="post">
  50. <cfoutput query="ticket">
  51. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  52. </cfoutput>
  53. <cfoutput query="attachment">
  54. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  55. </cfoutput>
  56. <table class="title">
  57. <thead>
  58. <tr>
  59. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  60. </th>
  61. </tr>
  62. </thead>
  63. </table>
  64.  
  65. <table style="100%" class="ticketlist">
  66. <col style="width:10%;" />
  67. <col style="width:3%;" />
  68. <col style="width:3%;" />
  69. <thead>
  70. <tr class="attachment" >
  71. <th>Attachment</th>
  72. <th>View</th>
  73. <th>Download</th>
  74. </tr>
  75. <thead>
  76. <tr>
  77. <td >
  78.  
  79. <cfoutput query="attachment">
  80. #description#
  81.  
  82.  
  83.  
  84. </td>
  85. <td align="center">
  86. <a href="attachments/#path#" target="_blank" >view</a>
  87. <br>
  88. </td>
  89. <td>
  90.  
  91.  
  92. <input type="hidden" name="confirmed" value="1">
  93. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  94. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  95.  
  96. </td>
  97. <td>
  98. <!---<cfcontent 
  99. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  100. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  101. deleteFile = "no">--->
  102. </td></cfoutput>
  103.  
  104. </tr>
  105. </table>
  106. </form>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#30: Oct 21 '08

re: How to delete and download attachments?


So what's happening now? Any errors?
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#31: Oct 21 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

So what's happening now? Any errors?

Hey Acoder,

Well its still giving me the site administrator error. An it only started happening when i moved the below from being underneath <cfquery name="attachment" to underneath the cfif form.confirmed.

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="getattachment" dbtype="query" >
  2. SELECT *
  3. FROM attachment
  4. WHERE pk_attachID=<cfqueryparam value="#form.attachID#" 
  5. cfsqltype="cf_sql_char" maxLength="20">
  6. </cfquery>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#32: Oct 21 '08

re: How to delete and download attachments?


What's the error message?

Note that #form.attachID# should be #form.pk_attachID#.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#33: Oct 21 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

What's the error message?

Note that #form.attachID# should be #form.pk_attachID#.

Hey Acoder,

Basically the error if gives me is site administrator that this error has occurred (be sure to include the contents of this page in your message to the administrator).So its not very helpful. But here is what i have in full. Do i need to have a hidden field for not only attachID but for pk_attachID as well?

Expand|Select|Wrap|Line Numbers
  1.     <cfparam name="form.confirmed" default="0">
  2.  
  3.  
  4.  
  5. <cfquery name="ticket" datasource="CustomerSupport">
  6.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  7.         FROM        
  8.         dbo.tbl_CS_ticketMaster
  9.         WHERE pk_ticketID = #URL.pk_ticketID#
  10. </cfquery>
  11.  
  12. <!---<cfquery name="attachment" datasource="CustomerSupport">
  13.          SELECT pk_attachID,fk_ticketID,description,path
  14.          FROM dbo.tbl_CS_attachments
  15.          WHERE fk_ticketID = #URL.pk_ticketID#
  16. </cfquery>--->
  17.  
  18. <cfquery name="attachment" datasource="CustomerSupport">
  19.          SELECT pk_attachID,fk_ticketID,description,path
  20.          FROM dbo.tbl_CS_attachments
  21.          WHERE fk_ticketID = #URL.pk_ticketID#
  22. </cfquery>
  23.  
  24.  
  25. <cfif form.confirmed EQ 1>
  26. <cfquery name="getattachment" dbtype="query" >
  27. SELECT *
  28. FROM attachment
  29. WHERE pk_attachID=<cfqueryparam value="#form.pk_attachID#" 
  30. cfsqltype="cf_sql_char" maxLength="20">
  31. </cfquery>
  32.  
  33. <cfquery name="deleteattachment" datasource="CustomerSupport">
  34.          DELETE 
  35.          FROM dbo.tbl_CS_attachments
  36.          WHERE pk_attachID = #URL.pk_ticketID#
  37. </cfquery>
  38. <cflock timeout="60">
  39. <cffile action="delete" 
  40. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
  41. </cflock>
  42. </cfif>
  43.  
  44. <script>
  45. function confirmDelete(delUrl) {
  46.   if (confirm("Are you sure you want to delete")) {
  47.     document.location = delUrl;
  48.   }
  49. }
  50. </script>
  51. </head>
  52. <body>
  53. <form method="post">
  54. <cfoutput query="ticket">
  55. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  56. </cfoutput>
  57. <cfoutput query="attachment">
  58. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  59. </cfoutput>
  60. <table class="title">
  61. <thead>
  62. <tr>
  63. <th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
  64. </th>
  65. </tr>
  66. </thead>
  67. </table>
  68.  
  69. <table style="100%" class="ticketlist">
  70. <col style="width:10%;" />
  71. <col style="width:3%;" />
  72. <col style="width:3%;" />
  73. <thead>
  74. <tr class="attachment" >
  75. <th>Attachment</th>
  76. <th>View</th>
  77. <th>Download</th>
  78. </tr>
  79. <thead>
  80. <tr>
  81. <td >
  82.  
  83. <cfoutput query="attachment">
  84. #description#
  85.  
  86.  
  87.  
  88. </td>
  89. <td align="center">
  90. <a href="attachments/#path#" target="_blank" >view</a>
  91. <br>
  92. </td>
  93. <td>
  94.  
  95.  
  96. <input type="hidden" name="confirmed" value="1">
  97. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  98. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  99.  
  100. </td>
  101. <td>
  102. <!---<cfcontent 
  103. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  104. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  105. deleteFile = "no">--->
  106. </td></cfoutput>
  107.  
  108. </tr>
  109. </table>
  110. </form>
  111.  
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#34: Oct 21 '08

re: How to delete and download attachments?


You already have a hidden field for pk_attachID. That should be enough. The error's probably caused by #path#. It needs to use this query's path. So set a variable path to #getattachment.path#
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#35: Oct 21 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

You already have a hidden field for pk_attachID. That should be enough. The error's probably caused by #path#. It needs to use this query's path. So set a variable path to #getattachment.path#

Hey Acoder,

well i figured out why nothing was displaying. It was having problem with this line. It was underneath form.
Expand|Select|Wrap|Line Numbers
  1. <cfoutput query="attachment">
  2. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  3. </cfoutput>
But anyway now i can see the attachments. But it still not deleting correctly. It deletes from the attachment folder but not from the table.Here is what i have.

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2. <cfquery name="ticket" datasource="CustomerSupport">
  3.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  4.         FROM        
  5.         dbo.tbl_CS_ticketMaster
  6.         WHERE pk_ticketID = #URL.pk_ticketID#
  7. </cfquery>
  8.  
  9. <cfquery name="attachment" datasource="CustomerSupport">
  10.          SELECT pk_attachID,fk_ticketID,description,path
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE fk_ticketID = #URL.pk_ticketID#
  13. </cfquery>
  14.  
  15.  
  16. <cfif form.confirmed EQ 1>
  17. <cfquery name="getattachment" dbtype="query" >
  18. SELECT *
  19. FROM attachment
  20. WHERE pk_attachID=<cfqueryparam value="#form.pk_attachID#" 
  21. cfsqltype="cf_sql_char" maxLength="120">
  22. </cfquery>
  23.  
  24. <cfquery name="deleteattachment" datasource="CustomerSupport">
  25.          DELETE 
  26.          FROM dbo.tbl_CS_attachments
  27.          WHERE pk_attachID = #URL.pk_ticketID#
  28. </cfquery>
  29. <cflock timeout="60">
  30. <cffile action="delete" 
  31. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  32. </cflock>
  33. </cfif>
  34.  
  35.  
  36. <script>
  37. function confirmDelete(delUrl) {
  38.   if (confirm("Are you sure you want to delete")) {
  39.     document.location = delUrl;
  40.   }
  41. }
  42. </script>
  43. </head>
  44. <body>
  45. <form method="post">
  46. <cfoutput query="ticket">
  47. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  48. </cfoutput>
  49. <!---<cfoutput query="attachment">
  50. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  51. </cfoutput>--->
  52.  
  53. <table class="title">
  54. <thead>
  55. <tr>
  56. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  57. </th>
  58. </tr>
  59. </thead>
  60. </table>
  61.  
  62. <table style="100%" class="ticketlist">
  63. <col style="width:10%;" />
  64. <col style="width:3%;" />
  65. <col style="width:3%;" />
  66. <thead>
  67. <tr class="attachment" >
  68. <th>Attachment</th>
  69. <th>View</th>
  70. <th>Download</th>
  71. </tr>
  72. <thead>
  73. <tr>
  74. <td >
  75.  
  76. <cfoutput query="attachment">
  77. #description#
  78.  
  79.  
  80.  
  81. </td>
  82. <td align="center">
  83. <a href="attachments/#path#" target="_blank" >view</a>
  84. <br>
  85. </td>
  86. <td>
  87.  
  88.  
  89. <input type="hidden" name="confirmed" value="1">
  90. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  91. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  92.  
  93. </td>
  94. <td>
  95. <!---<cfcontent 
  96. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  97. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  98. deleteFile = "no">--->
  99. </td></cfoutput>
  100.  
  101. </tr>
  102. </table>
  103. </form>
  104.  
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#36: Oct 21 '08

re: How to delete and download attachments?


The delete query should be matching the attachID:
Expand|Select|Wrap|Line Numbers
  1.  <cfquery name="deleteattachment" datasource="CustomerSupport">
  2.           DELETE 
  3.           FROM dbo.tbl_CS_attachments
  4.           WHERE pk_attachID = #form.pk_attachID#
  5.  </cfquery>
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#37: Oct 21 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

The delete query should be matching the attachID:

Expand|Select|Wrap|Line Numbers
  1.  <cfquery name="deleteattachment" datasource="CustomerSupport">
  2.           DELETE 
  3.           FROM dbo.tbl_CS_attachments
  4.           WHERE pk_attachID = #form.pk_attachID#
  5.  </cfquery>

Hey Acoder,

I did this

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="deleteattachment" datasource="CustomerSupport">
  2.          DELETE 
  3.          FROM dbo.tbl_CS_attachments
  4.          WHERE attachID = #URL.pk_ticketID#
  5. </cfquery>
an i got the following error
Query Manipulation Error Code = 0

Can't find symbol: attachID



SQL = "SELECT * FROM attachment WHERE attachID='72'"

Query Parameter Value(s) -

Parameter #1 = 72

Data Source = ""


The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (72:1) to (72:46)

Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#38: Oct 21 '08

re: How to delete and download attachments?


It should be pk_attachID, not attachID.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#39: Oct 21 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

It should be pk_attachID, not attachID.

Hey Acoder,

Ok here is what i have for all the coldfusion is this correct?

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2. <cfquery name="ticket" datasource="CustomerSupport">
  3.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  4.         FROM        
  5.         dbo.tbl_CS_ticketMaster
  6.         WHERE pk_ticketID = #URL.pk_ticketID#
  7. </cfquery>
  8.  
  9. <cfquery name="attachment" datasource="CustomerSupport">
  10.          SELECT pk_attachID,fk_ticketID,description,path
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE fk_ticketID = #URL.pk_ticketID#
  13. </cfquery>
  14.  
  15.  
  16. <cfif form.confirmed EQ 1>
  17. <cfquery name="getattachment" dbtype="query" >
  18. SELECT *
  19. FROM attachment
  20. WHERE attachID=<cfqueryparam value="#form.pk_attachID#" 
  21. cfsqltype="cf_sql_char" maxLength="120">
  22. </cfquery>
  23.  
  24. <cfquery name="deleteattachment" datasource="CustomerSupport">
  25.          DELETE 
  26.          FROM dbo.tbl_CS_attachments
  27.          WHERE pk_attachID = #URL.pk_ticketID#
  28. </cfquery>
  29. <cflock timeout="60">
  30. <cffile action="delete" 
  31. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  32. </cflock>
  33. </cfif>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#40: Oct 21 '08

re: How to delete and download attachments?


Look at the query I posted in #36. Use form.pk_attachID.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#41: Oct 21 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

Look at the query I posted in #36. Use form.pk_attachID.

Hey Acoder,

When i click delete i get this

Query Manipulation Error Code = 0

Can't find symbol: attachID



SQL = "SELECT * FROM attachment WHERE attachID='72'"

Query Parameter Value(s) -

Parameter #1 = 72

Data Source = ""


The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (72:1) to (72:46) in the template file C:\Inetpub\Development\WWWRoot\RachelB\footprints\ form\attachment.cfm.

here is what i have in full

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2. <cfquery name="ticket" datasource="CustomerSupport">
  3.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  4.         FROM        
  5.         dbo.tbl_CS_ticketMaster
  6.         WHERE pk_ticketID = #URL.pk_ticketID#
  7. </cfquery>
  8.  
  9. <cfquery name="attachment" datasource="CustomerSupport">
  10.          SELECT pk_attachID,fk_ticketID,description,path
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE fk_ticketID = #URL.pk_ticketID#
  13. </cfquery>
  14.  
  15.  
  16. <cfif form.confirmed EQ 1>
  17. <cfquery name="getattachment" dbtype="query" >
  18. SELECT *
  19. FROM attachment
  20. WHERE attachID=<cfqueryparam value="#form.pk_attachID#" 
  21. cfsqltype="cf_sql_char" maxLength="120">
  22. </cfquery>
  23.  
  24. <cfquery name="deleteattachment" datasource="CustomerSupport">
  25.          DELETE 
  26.          FROM dbo.tbl_CS_attachments
  27.          WHERE pk_attachID = #form.pk_attachID#
  28. </cfquery>
  29. <cflock timeout="60">
  30. <cffile action="delete" 
  31. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  32. </cflock>
  33. </cfif>
  34.  
  35.  
  36. <script>
  37. function confirmDelete(delUrl) {
  38.   if (confirm("Are you sure you want to delete")) {
  39.     document.location = delUrl;
  40.   }
  41. }
  42. </script>
  43. </head>
  44. <body>
  45. <form method="post">
  46. <cfoutput query="ticket">
  47. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  48. </cfoutput>
  49. <!---<cfoutput query="attachment">
  50. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  51. </cfoutput>--->
  52.  
  53. <table class="title">
  54. <thead>
  55. <tr>
  56. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  57. </th>
  58. </tr>
  59. </thead>
  60. </table>
  61.  
  62. <table style="100%" class="ticketlist">
  63. <col style="width:10%;" />
  64. <col style="width:3%;" />
  65. <col style="width:3%;" />
  66. <thead>
  67. <tr class="attachment" >
  68. <th>Attachment</th>
  69. <th>View</th>
  70. <th>Delete</th>
  71. <th>Download</th>
  72. </tr>
  73. <thead>
  74. <tr>
  75. <td >
  76.  
  77. <cfoutput query="attachment">
  78. #description#
  79.  
  80.  
  81.  
  82. </td>
  83. <td align="center">
  84. <a href="attachments/#path#" target="_blank" >view</a>
  85. <br>
  86. </td>
  87. <td>
  88.  
  89.  
  90. <input type="hidden" name="confirmed" value="1">
  91. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  92. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  93.  
  94. </td>
  95. <td>
  96. <!---<cfcontent 
  97. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  98. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  99. deleteFile = "no">--->
  100. </td></cfoutput>
  101.  
  102. </tr>
  103. </table>
  104. </form>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#42: Oct 22 '08

re: How to delete and download attachments?


In the getattachment query, you also need to use pk_attachID:
Expand|Select|Wrap|Line Numbers
  1. <cfquery name="getattachment" dbtype="query" >
  2. SELECT *
  3. FROM attachment
  4. WHERE pk_attachID=...
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#43: Oct 22 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

In the getattachment query, you also need to use pk_attachID:

Expand|Select|Wrap|Line Numbers
  1. <cfquery name="getattachment" dbtype="query" >
  2. SELECT *
  3. FROM attachment
  4. WHERE pk_attachID=...

Hey Acoder,

Not sure what i am doing wrong. But now its not deleting from attachments folder or database. Here is what i have in full.

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2. <cfquery name="ticket" datasource="CustomerSupport">
  3.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  4.         FROM        
  5.         dbo.tbl_CS_ticketMaster
  6.         WHERE pk_ticketID = #URL.pk_ticketID#
  7. </cfquery>
  8.  
  9. <cfquery name="attachment" datasource="CustomerSupport">
  10.          SELECT pk_attachID,fk_ticketID,description,path
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE fk_ticketID = #URL.pk_ticketID#
  13. </cfquery>
  14.  
  15.  
  16. <cfif form.confirmed EQ 1>
  17. <cfquery name="getattachment" dbtype="query" >
  18. SELECT *
  19. FROM attachment
  20. WHERE pk_attachID=<cfqueryparam value="#form.pk_attachID#" 
  21. cfsqltype="cf_sql_char" maxLength="120">
  22. </cfquery>
  23.  
  24. <cfquery name="deleteattachment" datasource="CustomerSupport">
  25.          DELETE 
  26.          FROM dbo.tbl_CS_attachments
  27.          WHERE pk_attachID = #form.pk_attachID#
  28. </cfquery>
  29. <cflock timeout="60">
  30. <cffile action="delete" 
  31. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  32. </cflock>
  33. </cfif>
  34.  
  35.  
  36. <script>
  37. function confirmDelete(delUrl) {
  38.   if (confirm("Are you sure you want to delete")) {
  39.     document.location = delUrl;
  40.   }
  41. }
  42. </script>
  43. </head>
  44. <body>
  45. <form method="post">
  46. <cfoutput query="ticket">
  47. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  48. </cfoutput>
  49. <!---<cfoutput query="attachment">
  50. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  51. </cfoutput>--->
  52.  
  53. <table class="title">
  54. <thead>
  55. <tr>
  56. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  57. </th>
  58. </tr>
  59. </thead>
  60. </table>
  61.  
  62.  
  63. <table style="100%" class="ticketlist">
  64. <col style="width:25%;" />
  65. <col style="width:10%;" />
  66. <col style="width:8%;" />
  67. <col style="width:8%;" />
  68. <thead>
  69. <tr class="attachment" >
  70. <th>Attachment</th>
  71. <th>View</th>
  72. <th>Delete</th>
  73. <th>Download</th>
  74. </tr>
  75. <thead>
  76. </table>
  77.  
  78. <cfoutput query="attachment">
  79. <table class="attachments">
  80. <tr>
  81. <td>
  82. #description#
  83. </td>
  84. <td class="view" align="center">
  85. <a href="attachments/#path#" target="_blank" >view</a>
  86. </td>
  87. <td align="center">
  88. <input type="hidden" name="confirmed" value="1">
  89. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  90. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  91. </td>
  92. <td align="center">
  93. download
  94. </td>
  95. <!---<td>
  96. <cfcontent 
  97. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  98. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  99. deleteFile = "no">
  100. </td>--->
  101. </tr>
  102. </table>
  103. </cfoutput>
  104. </form>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#44: Oct 22 '08

re: How to delete and download attachments?


Check the attach id value being passed (if you have debugging turned on which you should have) or output it using cfoutput (to test that it's correct).
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#45: Oct 22 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

Check the attach id value being passed (if you have debugging turned on which you should have) or output it using cfoutput (to test that it's correct).

Hey Acoder,

It is deleteing it from the database and from the attachments folder. But instead of once its deleteing it showing no attachments. It still shows the attachment there after i click delete. If i hit page refresh i get the following error

Expand|Select|Wrap|Line Numbers
  1. Error processing CFFILE
  2.  
  3. Unable to delete the file 'C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\.
is there anyway to make it where once the user deleted it, it doesn't show the file anymore? an is it possible that it display the message you have deleted the following file?

Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#46: Oct 22 '08

re: How to delete and download attachments?


That makes more sense.

To solve this problem, you need to move the delete to the top before the attachments query. This would cause the query of queries not to work, but that's not a problem. Either change getattachment to a normal query or include the path as a hidden field in the form (next to pk_attachID/confirmed). If you delete before running the attachment query, it will not show up in the page when deleted.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#47: Oct 22 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

That makes more sense.

To solve this problem, you need to move the delete to the top before the attachments query. This would cause the query of queries not to work, but that's not a problem. Either change getattachment to a normal query or include the path as a hidden field in the form (next to pk_attachID/confirmed). If you delete before running the attachment query, it will not show up in the page when deleted.

Hey Acoder,

i missed something,but not sure what, was trying to do it the first way you suggestion by changing the getattachment to a normal query. Here is what i have.

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2. <cfquery name="ticket" datasource="CustomerSupport">
  3.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  4.         FROM        
  5.         dbo.tbl_CS_ticketMaster
  6.         WHERE pk_ticketID = #URL.pk_ticketID#
  7. </cfquery>
  8.  
  9. <cfif form.confirmed EQ 1>
  10. <cfquery name="getattachment" datasource="CustomerSupport">
  11. SELECT *
  12. FROM attachment
  13. WHERE pk_attachID=<cfqueryparam value="#form.pk_attachID#" 
  14. cfsqltype="cf_sql_char" maxLength="120">
  15. </cfquery>
  16.  
  17. <cfquery name="deleteattachment" datasource="CustomerSupport">
  18.          DELETE 
  19.          FROM dbo.tbl_CS_attachments
  20.          WHERE pk_attachID = #form.pk_attachID#
  21. </cfquery>
  22. <cflock timeout="60">
  23. <cffile action="delete" 
  24. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  25. </cflock>
  26. </cfif>
  27.  
  28. <cfquery name="attachment" datasource="CustomerSupport">
  29.          SELECT pk_attachID,fk_ticketID,description,path
  30.          FROM dbo.tbl_CS_attachments
  31.          WHERE fk_ticketID = #URL.pk_ticketID#
  32. </cfquery>
  33.  
  34.  
  35.  
  36.  
  37.  
  38. <script>
  39. function confirmDelete(delUrl) {
  40.   if (confirm("Are you sure you want to delete")) {
  41.     document.location = delUrl;
  42.   }
  43. }
  44. </script>
  45. </head>
  46. <body>
  47. <form method="post">
  48. <cfoutput query="ticket">
  49. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  50. </cfoutput>
  51. <!---<cfoutput query="attachment">
  52. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  53. </cfoutput>--->
  54.  
  55. <table class="title">
  56. <thead>
  57. <tr>
  58. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  59. </th>
  60. </tr>
  61. </thead>
  62. </table>
  63.  
  64.  
  65. <table style="100%" class="ticketlist">
  66. <col style="width:25%;" />
  67. <col style="width:10%;" />
  68. <col style="width:8%;" />
  69. <col style="width:8%;" />
  70. <thead>
  71. <tr class="attachment" >
  72. <th>Attachment</th>
  73. <th>View</th>
  74. <th>Delete</th>
  75. <th>Download</th>
  76. </tr>
  77. <thead>
  78. </table>
  79.  
  80. <cfoutput query="attachment">
  81. <table class="attachments">
  82. <tr>
  83. <td>
  84. #description#
  85. </td>
  86. <td class="view" align="center">
  87. <a href="attachments/#path#" target="_blank" >view</a>
  88. </td>
  89. <td align="center">
  90. <input type="hidden" name="confirmed" value="1">
  91. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  92. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  93. </td>
  94. <td align="center">
  95. download
  96. </td>
  97. <!---<td>
  98. <cfcontent 
  99. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  100. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  101. deleteFile = "no">
  102. </td>--->
  103. </tr>
  104. </table>
  105. </cfoutput>
  106. </form>
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#48: Oct 22 '08

re: How to delete and download attachments?


Don't forget that the attachment query should now be the dbo.tbl_CS_attachments table.
Site Addict
 
Join Date: Aug 2008
Location: United States
Posts: 769
#49: Oct 22 '08

re: How to delete and download attachments?


Quote:

Originally Posted by acoder

Don't forget that the attachment query should now be the dbo.tbl_CS_attachments table.

Hey Acoder,

Here is what i have, but it wont let me delete anything right now.
Expand|Select|Wrap|Line Numbers
  1. <cfparam name="form.confirmed" default="0">
  2. <cfquery name="ticket" datasource="CustomerSupport">
  3.         SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
  4.         FROM        
  5.         dbo.tbl_CS_ticketMaster
  6.         WHERE pk_ticketID = #URL.pk_ticketID#
  7. </cfquery>
  8.  
  9. <cfif form.confirmed EQ 1>
  10. <cfquery name="getattachment" datasource="CustomerSupport">
  11. SELECT *
  12. FROM dbo.tbl_CS_attachments
  13. WHERE pk_attachID=<cfqueryparam value="#form.pk_attachID#" 
  14. cfsqltype="cf_sql_char" maxLength="120">
  15. </cfquery>
  16.  
  17. <cfquery name="deleteattachment" datasource="CustomerSupport">
  18.          DELETE 
  19.          FROM dbo.tbl_CS_attachments
  20.          WHERE pk_attachID = #form.pk_attachID#
  21. </cfquery>
  22. <cflock timeout="60">
  23. <cffile action="delete" 
  24. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  25. </cflock>
  26. </cfif>
  27.  
  28. <cfquery name="attachment" datasource="CustomerSupport">
  29.          SELECT pk_attachID,fk_ticketID,description,path
  30.          FROM dbo.tbl_CS_attachments
  31.          WHERE fk_ticketID = #URL.pk_ticketID#
  32. </cfquery>
  33.  
  34.  
  35.  
  36.  
  37.  
  38. <script>
  39. function confirmDelete(delUrl) {
  40.   if (confirm("Are you sure you want to delete")) {
  41.     document.location = delUrl;
  42.   }
  43. }
  44. </script>
  45. </head>
  46. <body>
  47. <form method="post">
  48. <cfoutput query="ticket">
  49. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  50. </cfoutput>
  51. <!---<cfoutput query="attachment">
  52. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  53. </cfoutput>--->
  54.  
  55. <table class="title">
  56. <thead>
  57. <tr>
  58. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  59. </th>
  60. </tr>
  61. </thead>
  62. </table>
  63.  
  64.  
  65. <table style="100%" class="ticketlist">
  66. <col style="width:25%;" />
  67. <col style="width:10%;" />
  68. <col style="width:8%;" />
  69. <col style="width:8%;" />
  70. <thead>
  71. <tr class="attachment" >
  72. <th>Attachment</th>
  73. <th>View</th>
  74. <th>Delete</th>
  75. <th>Download</th>
  76. </tr>
  77. <thead>
  78. </table>
  79.  
  80. <cfoutput query="attachment">
  81. <table class="attachments">
  82. <tr>
  83. <td>
  84. #description#
  85. </td>
  86. <td class="view" align="center">
  87. <a href="attachments/#path#" target="_blank" >view</a>
  88. </td>
  89. <td align="center">
  90. <input type="hidden" name="confirmed" value="1">
  91. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  92. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  93. </td>
  94. <td align="center">
  95. download
  96. </td>
  97. <!---<td>
  98. <cfcontent 
  99. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  100. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  101. deleteFile = "no">
  102. </td>--->
  103. </tr>
  104. </table>
  105. </cfoutput>
  106. </form>
  107.  
Thank you,
Rach
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#50: Oct 22 '08

re: How to delete and download attachments?


Do you get any errors? Make sure you're testing from a fresh page, not a submitted page.
Reply