469,326 Members | 1,423 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

How to delete and download attachments?

769 512MB
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
Oct 17 '08
107 9806
bonneylake
769 512MB
Do you get any errors? Make sure you're testing from a fresh page, not a submitted page.
Hey Acoder,

Yep that was the problem was trying to delete a previously submitted attachment. But how could i add a message telling the user after they delete the file been deleted? an how would i go about allowing the user to download an attachment to there computer?

This is all i have for it so far

Expand|Select|Wrap|Line Numbers
  1. <cfoutput query="attachment">
  2. <table class="attachments">
  3. <tr>
  4. <td>
  5. #description#
  6. </td>
  7. <td class="view" align="center">
  8. <a href="attachments/#path#" target="_blank" >view</a>
  9. </td>
  10. <td align="center">
  11. <input type="hidden" name="confirmed" value="1">
  12. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  13. <input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
  14. </td>
  15. <td align="center">
  16. download
  17. </td>
  18. <td>
  19. <cfcontent 
  20. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  21. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  22. deleteFile = "no">
  23. </td>
  24. </tr>
  25. </table>
  26. </cfoutput>
Thank you,
Rach
Oct 22 '08 #51
acoder
16,027 Expert Mod 8TB
You can display a message in the cfif (confirmed check) before the end tag. It's up to you if you want to put it in a div/span and style it to appear in the centre with a nice colour or whatever.
Oct 22 '08 #52
bonneylake
769 512MB
You can display a message in the cfif (confirmed check) before the end tag. It's up to you if you want to put it in a div/span and style it to appear in the centre with a nice colour or whatever.
Hey Acoder,

I think i still have a problem. Because with the delete, if i am displaying 2 files an i click on one file to delete it , it will not delete. But if i am displaying 1 file it will delete that one file, any ideas?

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>
but what i add the message i want to display after, or would i put it somewhere in the cfif below?

Expand|Select|Wrap|Line Numbers
  1. <cfif form.confirmed EQ 1>
  2. <cfquery name="getattachment" datasource="CustomerSupport">
  3. SELECT *
  4. FROM dbo.tbl_CS_attachments
  5. WHERE pk_attachID=<cfqueryparam value="#form.pk_attachID#" 
  6. cfsqltype="cf_sql_char" maxLength="120">
  7. </cfquery>
  8.  
  9. <cfquery name="deleteattachment" datasource="CustomerSupport">
  10.          DELETE 
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE pk_attachID = #form.pk_attachID#
  13. </cfquery>
  14. <cflock timeout="60">
  15. <cffile action="delete" 
  16. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  17. </cflock>
  18. </cfif>
Thank you,
Rach
Oct 22 '08 #53
acoder
16,027 Expert Mod 8TB
To answer the 2nd question first: yes, you would put it in the cfif. You may want to check that the file has indeed been deleted before displaying the messsage, so it may be an idea to attempt to delete the file first before removing the record from the database.

The delete problem is caused by the fact that all input fields are submitted. So the pk_attachID will be submitted as a list. You only need the one whose submit button was clicked. To solve this, you need to uniquely identify the attachment. You can either
1. pass it in the URL, or
2. use separate forms for each, or
3. have only one submit button, but use a checkbox to identify the attachments to be deleted.
Oct 23 '08 #54
bonneylake
769 512MB
To answer the 2nd question first: yes, you would put it in the cfif. You may want to check that the file has indeed been deleted before displaying the messsage, so it may be an idea to attempt to delete the file first before removing the record from the database.

The delete problem is caused by the fact that all input fields are submitted. So the pk_attachID will be submitted as a list. You only need the one whose submit button was clicked. To solve this, you need to uniquely identify the attachment. You can either
1. pass it in the URL, or
2. use separate forms for each, or
3. have only one submit button, but use a checkbox to identify the attachments to be deleted.
Hey Acoder,

Well how would i go about passing it in the url? mostly just confused on where i would apply the url at. I am use to doing a href= and the rest. An where in the cfif would i put it? after where i have it delete?

Thank you,
Rach
Oct 23 '08 #55
acoder
16,027 Expert Mod 8TB
Well how would i go about passing it in the url?
You could use JavaScript (if you know that everyone's got JavaScript enabled). If you don't want to depend on JavaScript, you'll have to use one of the other two methods.
An where in the cfif would i put it? after where i have it delete?
Yes.
Oct 23 '08 #56
bonneylake
769 512MB
You could use JavaScript (if you know that everyone's got JavaScript enabled). If you don't want to depend on JavaScript, you'll have to use one of the other two methods. Yes.
Hey Acoder,

Well i guess i should go with the 3rd option where it has a checkbox next to each an then they choose the delete button. Since no clue how many attachments they will add. But anyway i have no clue what to se the checkbox to so it knows what file to delete. 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 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. Your file has been deleted!
  27. </cfif>
  28.  
  29. <cfquery name="attachment" datasource="CustomerSupport">
  30.          SELECT pk_attachID,fk_ticketID,description,path
  31.          FROM dbo.tbl_CS_attachments
  32.          WHERE fk_ticketID = #URL.pk_ticketID#
  33. </cfquery>
  34.  
  35.  
  36.  
  37.  
  38.  
  39. <script>
  40. function confirmDelete(delUrl) {
  41.   if (confirm("Are you sure you want to delete")) {
  42.     document.location = delUrl;
  43.   }
  44. }
  45. </script>
  46. </head>
  47. <body>
  48. <form method="post">
  49. <cfoutput query="ticket">
  50. <input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
  51. </cfoutput>
  52. <!---<cfoutput query="attachment">
  53. <input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
  54. </cfoutput>--->
  55.  
  56. <table class="title">
  57. <thead>
  58. <tr>
  59. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  60. </th>
  61. </tr>
  62. </thead>
  63. </table>
  64.  
  65.  
  66. <table style="100%" class="ticketlist">
  67. <col style="width:25%;" />
  68. <col style="width:10%;" />
  69. <col style="width:8%;" />
  70. <col style="width:8%;" />
  71. <thead>
  72. <tr class="attachment" >
  73. <th>Attachment</th>
  74. <th>View</th>
  75. <th>Delete</th>
  76. <th>Download</th>
  77. </tr>
  78. <thead>
  79. </table>
  80.  
  81. <cfoutput query="attachment">
  82. <table class="attachments">
  83. <tr>
  84. <td>
  85. #description#
  86. </td>
  87. <td class="view" align="center">
  88. <a href="attachments/#path#" target="_blank" >view</a>
  89. </td>
  90. <td align="center">
  91. <input type="hidden" name="confirmed" value="1">
  92. <input type="hidden" name="pk_attachID" value="#pk_attachID#">
  93. <input type="checkbox" name="2" value="2">
  94. </td>
  95. <td align="center">
  96. download
  97. </td>
  98. <!---<td>
  99. <cfcontent 
  100. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  101. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  102. deleteFile = "no">
  103. </td>--->
  104. </tr>
  105. </table>
  106. <center><input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')"></center>
  107. </cfoutput>
  108. </form>
Thank you,
Rach
Oct 23 '08 #57
acoder
16,027 Expert Mod 8TB
You could just use the pk_attachID hidden field and set it to "checkbox" instead of "hidden". This will allow you to delete a number of attachments at once instead of one at a time. You will need to use a loop over the form.pk_attachID values for the deletion.
Oct 23 '08 #58
bonneylake
769 512MB
You could just use the pk_attachID hidden field and set it to "checkbox" instead of "hidden". This will allow you to delete a number of attachments at once instead of one at a time. You will need to use a loop over the form.pk_attachID values for the deletion.
Hey Acoder,

What type of cfloop would i use? like a cfloop query? an would i apply it to just around the checkbox or would i put the loop around the entire form?

Thank you,
Rach
Oct 23 '08 #59
acoder
16,027 Expert Mod 8TB
No, this loop is for the actual deleting, so it would go at the top. It can replace the cfif confirmed check because you can just loop the list and if it's empty nothing is deleted. You would use a cfloop looping over a list.
Oct 23 '08 #60
bonneylake
769 512MB
No, this loop is for the actual deleting, so it would go at the top. It can replace the cfif confirmed check because you can just loop the list and if it's empty nothing is deleted. You would use a cfloop looping over a list.
Hey Acoder,

I added the list but i am not sure where i would put "del" at. would i put it at underneath file has been deleted wrapped around <cfoutput>?

Expand|Select|Wrap|Line Numbers
  1. <cfloop index="del" list="form.confirmed">
  2. <cfquery name="getattachment" datasource="CustomerSupport">
  3. SELECT *
  4. FROM dbo.tbl_CS_attachments
  5. WHERE pk_attachID=<cfqueryparam value="#form.pk_attachID#" 
  6. cfsqltype="cf_sql_char" maxLength="120">
  7. </cfquery>
  8.  
  9. <cfquery name="deleteattachment" datasource="CustomerSupport">
  10.          DELETE 
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE pk_attachID = #form.pk_attachID#
  13. </cfquery>
  14. <cflock timeout="60">
  15. <cffile action="delete" 
  16. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  17. </cflock>
  18. Your file has been deleted!
  19. </cfloop>
Thank you,
Rach
Oct 23 '08 #61
acoder
16,027 Expert Mod 8TB
#del# would replace #form.pk_attachID#.

Note that you need to loop over #form.pk_attachID#, not form.confirmed.
Oct 23 '08 #62
bonneylake
769 512MB
#del# would replace #form.pk_attachID#.

Note that you need to loop over #form.pk_attachID#, not form.confirmed.
Hey Acoder,

So like this correct?

Expand|Select|Wrap|Line Numbers
  1. <cfloop index="del" list="form.pk_attachID">
  2. <cfquery name="getattachment" datasource="CustomerSupport">
  3. SELECT *
  4. FROM dbo.tbl_CS_attachments
  5. WHERE pk_attachID=<cfqueryparam value="#del#" 
  6. cfsqltype="cf_sql_char" maxLength="120">
  7. </cfquery>
  8.  
  9. <cfquery name="deleteattachment" datasource="CustomerSupport">
  10.          DELETE 
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE pk_attachID = #del#
  13. </cfquery>
  14. <cflock timeout="60">
  15. <cffile action="delete" 
  16. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  17. </cflock>
  18. Your file has been deleted!
  19. </cfloop>
Thank you,
Rach
Oct 23 '08 #63
acoder
16,027 Expert Mod 8TB
Almost - form.pk_attachID needs to be in ##
Oct 23 '08 #64
bonneylake
769 512MB
Almost - form.pk_attachID needs to be in ##
Hey Acoder,

Well i tried that an it said error resolving parameter #Form.pk_attachID# the one in the list. 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. <!---<cfif form.confirmed EQ 1>--->
  10. <cfloop index="del" list="#Form.pk_attachID#">
  11. <cfquery name="getattachment" datasource="CustomerSupport">
  12. SELECT *
  13. FROM dbo.tbl_CS_attachments
  14. WHERE pk_attachID=<cfqueryparam value="#del#" 
  15. cfsqltype="cf_sql_char" maxLength="120">
  16. </cfquery>
  17.  
  18. <cfquery name="deleteattachment" datasource="CustomerSupport">
  19.          DELETE 
  20.          FROM dbo.tbl_CS_attachments
  21.          WHERE pk_attachID = #del#
  22. </cfquery>
  23. <cflock timeout="60">
  24. <cffile action="delete" 
  25. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  26. </cflock>
  27. Your file has been deleted!
  28. <!---</cfif>--->
  29. </cfloop>
  30.  
  31. <cfquery name="attachment" datasource="CustomerSupport">
  32.          SELECT pk_attachID,fk_ticketID,description,path
  33.          FROM dbo.tbl_CS_attachments
  34.          WHERE fk_ticketID = #URL.pk_ticketID#
  35. </cfquery>
  36.  
  37.  
  38.  
  39.  
  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="attachID" id="attachID" value="#form.attachID#" />
  56. </cfoutput>--->
  57.  
  58. <table class="title">
  59. <thead>
  60. <tr>
  61. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  62. </th>
  63. </tr>
  64. </thead>
  65. </table>
  66.  
  67.  
  68. <table style="100%" class="ticketlist">
  69. <col style="width:25%;" />
  70. <col style="width:10%;" />
  71. <col style="width:8%;" />
  72. <col style="width:8%;" />
  73. <thead>
  74. <tr class="attachment" >
  75. <th>Attachment</th>
  76. <th>View</th>
  77. <th>Delete</th>
  78. <th>Download</th>
  79. </tr>
  80. <thead>
  81. </table>
  82.  
  83. <cfoutput query="attachment">
  84. <table class="attachments">
  85. <tr>
  86. <td>
  87. #description#
  88. </td>
  89. <td class="view" align="center">
  90. <a href="attachments/#path#" target="_blank" >view</a>
  91. </td>
  92. <td align="center">
  93. <input type="hidden" name="confirmed" value="1">
  94. <input type="checkbox" name="pk_attachID" value="#pk_attachID#">
  95. </td>
  96. <td align="center">
  97. download
  98. </td>
  99. <!---<td>
  100. <cfcontent 
  101. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  102. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  103. deleteFile = "no">
  104. </td>--->
  105. </tr>
  106. </table>
  107. </cfoutput>
  108. <center><input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')"></center>
  109. </form>
Thank you,
Rach
Oct 23 '08 #65
acoder
16,027 Expert Mod 8TB
That'll be because you didn't check a checkbox and to get rid of the error when no attachments are checked, you need to use cfparam for pk_attachID.
Oct 23 '08 #66
bonneylake
769 512MB
That'll be because you didn't check a checkbox and to get rid of the error when no attachments are checked, you need to use cfparam for pk_attachID.
Hey Acoder,

is this correct?

Expand|Select|Wrap|Line Numbers
  1. <cfloop index="del" list="<cfqueryparam value="#Form.pk_attachID#" CFSQLType = "CF_SQL_VARCHAR">">
  2. <cfquery name="getattachment" datasource="CustomerSupport">
  3. SELECT *
  4. FROM dbo.tbl_CS_attachments
  5. WHERE pk_attachID=<cfqueryparam value="#del#" 
  6. cfsqltype="cf_sql_char" maxLength="120">
  7. </cfquery>
  8.  
  9. <cfquery name="deleteattachment" datasource="CustomerSupport">
  10.          DELETE 
  11.          FROM dbo.tbl_CS_attachments
  12.          WHERE pk_attachID = #del#
  13. </cfquery>
  14. <cflock timeout="60">
  15. <cffile action="delete" 
  16. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  17. </cflock>
  18. Your file has been deleted!
  19. <!---</cfif>--->
  20. </cfloop>
Thank you,
Rach
Oct 23 '08 #67
acoder
16,027 Expert Mod 8TB
Not a cfqueryparam! That goes in a cfquery. I meant cfparam like you have for form.confirmed at the top.
Oct 23 '08 #68
bonneylake
769 512MB
Not a cfqueryparam! That goes in a cfquery. I meant cfparam like you have for form.confirmed at the top.
Hey Acoder,

Here is what i have for it. Do i need to set a default?

Expand|Select|Wrap|Line Numbers
  1. <cfloop index="del" list="<cfparam name="#Form.pk_attachID#">">
Thank you,
Rach
Oct 23 '08 #69
acoder
16,027 Expert Mod 8TB
Not in the list attribute. That'd be invalid syntax. At the top on its own like form.confirmed.
Oct 23 '08 #70
bonneylake
769 512MB
Not in the list attribute. That'd be invalid syntax. At the top on its own like form.confirmed.
Hey Acoder,

Ok here is what i got, this correct?

Expand|Select|Wrap|Line Numbers
  1. <cfparam name="#Form.pk_attachID#">
  2. <cfloop index="del" list="Form.pk_attachID">
  3. <cfquery name="getattachment" datasource="CustomerSupport">
  4. SELECT *
  5. FROM dbo.tbl_CS_attachments
  6. WHERE pk_attachID=<cfqueryparam value="#del#" 
  7. cfsqltype="cf_sql_char" maxLength="120">
  8. </cfquery>
  9.  
  10. <cfquery name="deleteattachment" datasource="CustomerSupport">
  11.          DELETE 
  12.          FROM dbo.tbl_CS_attachments
  13.          WHERE pk_attachID = #del#
  14. </cfquery>
  15. <cflock timeout="60">
  16. <cffile action="delete" 
  17. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  18. </cflock>
  19. Your file has been deleted!
  20. </cfloop>
Thank you,
Rach
Oct 23 '08 #71
acoder
16,027 Expert Mod 8TB
Still two things:
Why have you removed the ## from form.pk_attachID in cfloop list= ?
You need to set the default attribute too in the cfparam.
Oct 24 '08 #72
bonneylake
769 512MB
Hey Acoder,

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.  
  10. <cfparam name="#Form.pk_attachID#" default="0">
  11. <cfloop index="del" list="#Form.pk_attachID#">
  12. <cfquery name="getattachment" datasource="CustomerSupport">
  13. SELECT *
  14. FROM dbo.tbl_CS_attachments
  15. WHERE pk_attachID=<cfqueryparam value="#del#" 
  16. cfsqltype="cf_sql_char" maxLength="120">
  17. </cfquery>
  18.  
  19. <cfquery name="deleteattachment" datasource="CustomerSupport">
  20.          DELETE 
  21.          FROM dbo.tbl_CS_attachments
  22.          WHERE pk_attachID = #del#
  23. </cfquery>
  24. <cflock timeout="60">
  25. <cffile action="delete" 
  26. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  27. </cflock>
  28. Your file has been deleted!
  29. </cfloop>
  30.  
  31. <cfquery name="attachment" datasource="CustomerSupport">
  32.          SELECT pk_attachID,fk_ticketID,description,path
  33.          FROM dbo.tbl_CS_attachments
  34.          WHERE fk_ticketID = #URL.pk_ticketID#
  35. </cfquery>
  36.  
  37.  
  38.  
  39.  
  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="attachID" id="attachID" value="#form.attachID#" />
  56. </cfoutput>--->
  57.  
  58. <table class="title">
  59. <thead>
  60. <tr>
  61. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  62. </th>
  63. </tr>
  64. </thead>
  65. </table>
  66.  
  67.  
  68. <table style="100%" class="ticketlist">
  69. <col style="width:25%;" />
  70. <col style="width:10%;" />
  71. <col style="width:8%;" />
  72. <col style="width:8%;" />
  73. <thead>
  74. <tr class="attachment" >
  75. <th>Attachment</th>
  76. <th>View</th>
  77. <th>Delete</th>
  78. <th>Download</th>
  79. </tr>
  80. <thead>
  81. </table>
  82.  
  83. <cfoutput query="attachment">
  84. <table class="attachments">
  85. <tr>
  86. <td>
  87. #description#
  88. </td>
  89. <td class="view" align="center">
  90. <a href="attachments/#path#" target="_blank" >view</a>
  91. </td>
  92. <td align="center">
  93. <input type="hidden" name="confirmed" value="1">
  94. <input type="checkbox" name="pk_attachID" value="#pk_attachID#">
  95. </td>
  96. <td align="center">
  97. download
  98. </td>
  99. <!---<td>
  100. <cfcontent 
  101. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  102. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  103. deleteFile = "no">
  104. </td>--->
  105. </tr>
  106. </table>
  107. </cfoutput>
  108. <center><input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')"></center>
  109. </form>
Oct 24 '08 #73
acoder
16,027 Expert Mod 8TB
Since it's a list, the default should be the empty string. Test it now and see if it works.
Oct 24 '08 #74
bonneylake
769 512MB
Since it's a list, the default should be the empty string. Test it now and see if it works.
Hey Acoder,

i get the error Error resolving parameter FORM.PK_ATTACHID
an it says its the cfparam line its having trouble with. 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. <!---<cfif form.confirmed EQ 1>--->
  10. <cfparam name="#Form.pk_attachID#" default="">
  11. <cfloop index="del" list="#Form.pk_attachID#">
  12. <cfquery name="getattachment" datasource="CustomerSupport">
  13. SELECT *
  14. FROM dbo.tbl_CS_attachments
  15. WHERE pk_attachID=<cfqueryparam value="#del#" 
  16. cfsqltype="cf_sql_char" maxLength="120">
  17. </cfquery>
  18.  
  19. <cfquery name="deleteattachment" datasource="CustomerSupport">
  20.          DELETE 
  21.          FROM dbo.tbl_CS_attachments
  22.          WHERE pk_attachID = #del#
  23. </cfquery>
  24. <cflock timeout="60">
  25. <cffile action="delete" 
  26. file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
  27. </cflock>
  28. Your file has been deleted!
  29. <!---</cfif>--->
  30. </cfloop>
  31.  
  32. <cfquery name="attachment" datasource="CustomerSupport">
  33.          SELECT pk_attachID,fk_ticketID,description,path
  34.          FROM dbo.tbl_CS_attachments
  35.          WHERE fk_ticketID = #URL.pk_ticketID#
  36. </cfquery>
  37.  
  38.  
  39.  
  40.  
  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="attachID" id="attachID" value="#form.attachID#" />
  57. </cfoutput>--->
  58.  
  59. <table class="title">
  60. <thead>
  61. <tr>
  62. <th>Previously Submitted Attachments to ticket <cfoutput query="ticket">#pk_ticketID#</cfoutput>
  63. </th>
  64. </tr>
  65. </thead>
  66. </table>
  67.  
  68.  
  69. <table style="100%" class="ticketlist">
  70. <col style="width:25%;" />
  71. <col style="width:10%;" />
  72. <col style="width:8%;" />
  73. <col style="width:8%;" />
  74. <thead>
  75. <tr class="attachment" >
  76. <th>Attachment</th>
  77. <th>View</th>
  78. <th>Delete</th>
  79. <th>Download</th>
  80. </tr>
  81. <thead>
  82. </table>
  83.  
  84. <cfoutput query="attachment">
  85. <table class="attachments">
  86. <tr>
  87. <td>
  88. #description#
  89. </td>
  90. <td class="view" align="center">
  91. <a href="attachments/#path#" target="_blank" >view</a>
  92. </td>
  93. <td align="center">
  94. <input type="hidden" name="confirmed" value="1">
  95. <input type="checkbox" name="pk_attachID" value="#pk_attachID#">
  96. </td>
  97. <td align="center">
  98. download
  99. </td>
  100. <!---<td>
  101. <cfcontent 
  102. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  103. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  104. deleteFile = "no">
  105. </td>--->
  106. </tr>
  107. </table>
  108. </cfoutput>
  109. <center><input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')"></center>
  110. </form>
Thank you,
Rach
Oct 24 '08 #75
acoder
16,027 Expert Mod 8TB
The element name shouldn't be in ##s in cfparam.
Oct 24 '08 #76
bonneylake
769 512MB
The element name shouldn't be in ##s in cfparam.
Hey Acoder,

Yay it works!!! i just want to cry it looks so pretty. But ok so how would i do the download part? so far all i have is an it appears under the delete button

Expand|Select|Wrap|Line Numbers
  1. <cfcontent 
  2. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  3. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  4. deleteFile = "no">  
Thank you :),
Rach
Oct 24 '08 #77
acoder
16,027 Expert Mod 8TB
For the download part, you need to link to another Coldfusion page which has a cfheader/cfcontent set on the page. See the documentation for those two tags to get some useful tips.
Oct 24 '08 #78
bonneylake
769 512MB
For the download part, you need to link to another Coldfusion page which has a cfheader/cfcontent set on the page. See the documentation for those two tags to get some useful tips.
Hey Acoder,

So let me get this straight from what i read, based on this link

http://livedocs.adobe.com/coldfusion...gs_g-h_07.html
. Basically i would put this on the attachment page i have now the below

Expand|Select|Wrap|Line Numbers
  1. <cfheader name="Content-Disposition" value="attachment; filename=filename.ext">
an then on the filename.ext i would put the cfcontent correct?

Expand|Select|Wrap|Line Numbers
  1. <cfcontent 
  2.     deleteFile = "yes|no"
  3.     file = "filename"
  4.     reset = "yes|no"
  5.     type = "file type"
  6.     variable = "variable name">
Thank you,
Rach
Oct 24 '08 #79
acoder
16,027 Expert Mod 8TB
filename.ext is just an example. You should replace that with the actual file name and extension of the file to be downloaded. See some of the examples in the cfcontent doc page.
Oct 24 '08 #80
bonneylake
769 512MB
filename.ext is just an example. You should replace that with the actual file name and extension of the file to be downloaded. See some of the examples in the cfcontent doc page.
Hey Acoder,

Ok i looked at the examples on there. An ok this is all on the attachment page. Is this correct?

Expand|Select|Wrap|Line Numbers
  1. <cfheader name="Content-Disposition" value="attachment; filename=#path#">
  2. <cfcontent 
  3. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  4. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  5. >
  6.  
Thank you,
Rach
Oct 24 '08 #81
acoder
16,027 Expert Mod 8TB
You should change the type to whatever the content type is - not a whole list. Also make sure #path# is set somewhere. This would be in a new page, so the path would be passed in the URL.
Oct 24 '08 #82
bonneylake
769 512MB
You should change the type to whatever the content type is - not a whole list. Also make sure #path# is set somewhere. This would be in a new page, so the path would be passed in the URL.
Hey Acoder,

Well the reason i have a whole list is i have no clue what they will be uploading, it could be a picture,word,excel really anything so tried to leave it open. An i am confused by the second page. Would everything go on a second page? an then for the download do i need to create a url method?

Thank you,
Rach
Oct 24 '08 #83
acoder
16,027 Expert Mod 8TB
Yes, everything would go on another page and then pass the path of the attachment to this page.

Determine the type from the extension and pass the correct type, not a list.
Oct 24 '08 #84
bonneylake
769 512MB
Yes, everything would go on another page and then pass the path of the attachment to this page.

Determine the type from the extension and pass the correct type, not a list.
Hey Acoder,

Ok so on the first page is
Expand|Select|Wrap|Line Numbers
  1. <a href="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\download.cfm"><input type="submit" value="download"></a>
an then on the second page is

Expand|Select|Wrap|Line Numbers
  1. <cfheader name="Content-Disposition" value="attachment; filename=#path#">
  2. <cfcontent 
  3. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  4. type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
  5. >
do i need to on the second page wrap it all in a cfoutput?

an how would i determine the type based on the extension? didn't see anything on the doc page for cfcontent.

Thank you,
Rach
Oct 24 '08 #85
acoder
16,027 Expert Mod 8TB
Ok so on the first page is
Expand|Select|Wrap|Line Numbers
  1. <a href="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\download.cfm"><input type="submit" value="download"></a>
Don't put a submit button - just text will do. The href shouldn't be to the full path and certainly not the Windows path - just a relative path, e.g. "download.cfm". You should pass the path here, so add a parameter for path.

do i need to on the second page wrap it all in a cfoutput?
No, you don't. You'll need to get the path passed to the page. Use that in place of #path#.

an how would i determine the type based on the extension? didn't see anything on the doc page for cfcontent.
Yes, it isn't there. That was just a suggestion. You should know what the type is already. If you don't, then use the extension to determine it, e.g. ".xls" would be an Excel file, .doc would be a Word document, .jpg would be a JPEG image, etc.
Oct 24 '08 #86
bonneylake
769 512MB
Don't put a submit button - just text will do. The href shouldn't be to the full path and certainly not the Windows path - just a relative path, e.g. "download.cfm". You should pass the path here, so add a parameter for path.

No, you don't. You'll need to get the path passed to the page. Use that in place of #path#.

Yes, it isn't there. That was just a suggestion. You should know what the type is already. If you don't, then use the extension to determine it, e.g. ".xls" would be an Excel file, .doc would be a Word document, .jpg would be a JPEG image, etc.
Hey Acoder,

so is this correct for passing the path? reason i had it wrapped around a button cause wanted it to be a button (eventually) since the delete is a button would make since to make it a button as well.

Expand|Select|Wrap|Line Numbers
  1. <a href="download.cfm?path=#path#">download</a>
an my bad i thought i needed to use something different instead of type= to get it going on the extension.

Thank you,
Rach
Oct 24 '08 #87
acoder
16,027 Expert Mod 8TB
To use a button instead, you can use something like:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" onclick="window.location.href='download.cfm?path=#path#'">
You may want to encode the path value to avoid problems with special characters.
Oct 24 '08 #88
bonneylake
769 512MB
To use a button instead, you can use something like:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" onclick="window.location.href='download.cfm?path=#path#'">
You may want to encode the path value to avoid problems with special characters.
Hey Acoder,

What you mean encode the path value to avoid problems? how would i do that?

Thank you,
Rach
Oct 24 '08 #89
acoder
16,027 Expert Mod 8TB
You can use encodeURIComponent (a JavaScript function) to encode the value. In the download page, the path would be available in url.path, though you'd want to cfparam too just in case. Did you manage to work out the type of attachments? You may want to consider storing this information in the database - not necessary, but may be useful.
Oct 25 '08 #90
bonneylake
769 512MB
You can use encodeURIComponent (a JavaScript function) to encode the value. In the download page, the path would be available in url.path, though you'd want to cfparam too just in case. Did you manage to work out the type of attachments? You may want to consider storing this information in the database - not necessary, but may be useful.

Hey Acoder,

Would i do the type of attachment like so, i was not sure what to put for application/x-shockwave-flash.

Expand|Select|Wrap|Line Numbers
  1. <cfheader name="Content-Disposition" value="attachment; filename=#path#">
  2. <cfcontent 
  3. file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" 
  4. type=".html,.txt,.jpg,.gif,.doc,.xls,.mdb,.ppt,application/x-shockwave-flash;"
  5. >
an i am a bit confused on the encodeURIComponent. i found this
http://www.w3schools.com/jsref/jsref...IComponent.asp
i am not sure if i would put this on my attachment file or my download file?.

Thank you,
Rach
Oct 27 '08 #91
acoder
16,027 Expert Mod 8TB
No, the type should be as you had it before, but one only rather than a list. You'll have to work out what the type should be and use that one type, not a list.

encodeURIComponent is a JS function, so it would go round the #path# variable in the button code.
Oct 27 '08 #92
bonneylake
769 512MB
No, the type should be as you had it before, but one only rather than a list. You'll have to work out what the type should be and use that one type, not a list.

encodeURIComponent is a JS function, so it would go round the #path# variable in the button code.

Hey Acoder,

The only thing i am not sure of is what type of encodeURIComponent i should use because they have 3 examples, 2 use the address an the other uses a bunch of different symbols. This is what i have, but i know it aint right. Just not sure how to go about it
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. document.write(encodeURIComponent("http://www.w3schools.com"));
  3. <input type="button" name="download" value="Download" onClick="window.location.href='download.cfm?path=#path#'">
  4. </script>
Thank you,
Rach
Oct 27 '08 #93
acoder
16,027 Expert Mod 8TB
The #path# value is the address, so you need something like:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" onClick="window.location.href='download.cfm?path=encodeURIComponent(#path#)'">
Oct 27 '08 #94
bonneylake
769 512MB
The #path# value is the address, so you need something like:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" onClick="window.location.href='download.cfm?path=encodeURIComponent(#path#)'">
Hey Acoder,

So would i move this part to the top of the page
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. document.write(encodeURIComponent("http://www.w3schools.com"));
  3. </script>
and leave the button like so

Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" onClick="window.location.href='download.cfm?path=encodeURIComponent(#path#)'">
an then what would i put instead of the www.w3schools.com, would i put
C:\Inetpub\Development\WWWRoot\RachelB\footprints\ form\attachments\ or
something else?

Thank you,
Rach
Oct 27 '08 #95
acoder
16,027 Expert Mod 8TB
No, that was only an example. What you need is contained within that button. The rest you can ignore.
Oct 27 '08 #96
bonneylake
769 512MB
No, that was only an example. What you need is contained within that button. The rest you can ignore.
Hey Acoder,

so your saying i don't need this at all?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. document.write(encodeURIComponent("http://www.w3schools.com"));
  3.  </script>
or that i don't need the address like so

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. document.write(encodeURIComponent(""));
  3. </script>
  4.  
Thank you,
Rach
Oct 27 '08 #97
acoder
16,027 Expert Mod 8TB
No, you don't need any of that - just the button.
Oct 27 '08 #98
bonneylake
769 512MB
No, you don't need any of that - just the button.
Hey Acoder,

well the encode didn't work, when i try to download it says it cant find the file, you said something about cfparam, what would i set the cfparam to?
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" onClick="window.location.href='download.cfm?path=encodeURIComponent(#path#)'">
Thank you,
Rach
Oct 27 '08 #99
acoder
16,027 Expert Mod 8TB
The cfparam is just there in case a path is not specified. You can set it to the empty string, then when outputting, if it's empty, you can just display a message instead of trying to download the file.

In download.cfm, have you changed the type attribute for the cfcontent tag? Note that you can force a download by setting the type to "application/unknown". That might be simplest solution in this case.
Oct 27 '08 #100

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by David Barrett | last post: by
2 posts views Thread by Bob Greschke | last post: by
1 post views Thread by Ray | last post: by
4 posts views Thread by Li Weng | last post: by
16 posts views Thread by Philip Boonzaaier | last post: by
4 posts views Thread by Seguros Catatumbo | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.