469,366 Members | 2,362 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 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 9820
bonneylake
769 512MB
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.

Hey Acoder,

Tried to set the type to what you said an well i am still getting the same error. Here is what it says.

No such file.

The file specified in CFContent does not exist: C:\Inetpub\Development\WWWRoot\RachelB\footprints\ form\attachments\encodeURIComponent(capt.108c1e44b 23c48a59fd6d459b143331f_386_3.jpg)

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


an this is what i have on the download page.

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="application/unknown"
  5. >
Thank you,
Rach
Oct 27 '08 #101
acoder
16,027 Expert Mod 8TB
Obviously, it's not going to work (gah!). It should be:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" onClick="window.location.href='download.cfm?path='+encodeURIComponent(#path#);">
Note that the previous code was putting encodeURIComponent within the URL resulting in the "No such file" error.
Oct 27 '08 #102
bonneylake
769 512MB
Obviously, it's not going to work (gah!). It should be:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" onClick="window.location.href='download.cfm?path='+encodeURIComponent(#path#);">
Note that the previous code was putting encodeURIComponent within the URL resulting in the "No such file" error.
Hey Acoder,

i am getting a weird error. It says

Error: missing ) after argument list
Source Code:
window.location.href='download.cfm?path='+encodeUR IComponent(capt.2e780c0734e006b13d9c3f793cd88715_3 86_2.jpg);

it says its missing after capt. an here is what i have for the button
Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" 
  2. onClick="window.location.href='download.cfm?path='+encodeURIComponent(#path#);">
Thank you,
Rach
Oct 27 '08 #103
acoder
16,027 Expert Mod 8TB
Remove the spaces between UR and IC
Oct 27 '08 #104
bonneylake
769 512MB
Remove the spaces between UR and IC
Hey Acoder,

I don't know why but only when i put the code on here it shows the space between UR and IC even when i make sure it don't have a space between it before i submit.
but in my code its all together.

Expand|Select|Wrap|Line Numbers
  1. <input type="button" name="download" value="Download" 
  2. onClick="window.location.href='download.cfm?path='+encodeURIComponent(#path#);
  3. ">

Thank you,
Rach
Oct 27 '08 #105
acoder
16,027 Expert Mod 8TB
I see what's happening now. #path# is being converted to a string without quotes which JavaScript doesn't recognise. Either set #path# to a JavaScript variable, or just put it in quotes:
Expand|Select|Wrap|Line Numbers
  1. encodeURIComponent('#path#')
Oct 27 '08 #106
bonneylake
769 512MB
I see what's happening now. #path# is being converted to a string without quotes which JavaScript doesn't recognise. Either set #path# to a JavaScript variable, or just put it in quotes:
Expand|Select|Wrap|Line Numbers
  1. encodeURIComponent('#path#')
Hey Acoder,

That was it, it just needed the quotes. THANK YOU, THANK YOU!!! Thank you so much for all your help, it is awesome to see it downloading and deleting files :).
Thank you again :),
Rach
Oct 27 '08 #107
acoder
16,027 Expert Mod 8TB
Oh, you're welcome! Glad it's working.
Oct 27 '08 #108

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
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.