473,715 Members | 2,766 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to delete and download attachments?

769 Contributor
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 #1
107 11314
acoder
16,027 Recognized Expert Moderator MVP
We'll deal with one thing at a time. Deleting first. Where's the delete query?
Oct 17 '08 #2
bonneylake
769 Contributor
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
Oct 17 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
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.
Oct 17 '08 #4
bonneylake
769 Contributor
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
Oct 17 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
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.
Oct 17 '08 #6
bonneylake
769 Contributor
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
Oct 17 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Put the delete query first before running any queries showing the attachments.
Oct 20 '08 #8
bonneylake
769 Contributor
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
Oct 20 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
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.
Oct 20 '08 #10

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

Similar topics

0
1247
by: David Barrett | last post by:
I'm proud to announce the completion of QwikiWiki v1.4.1, available for download now! QwikiWiki has the fastest installation, easiest syntax, and the fewest, highest-value features of any wiki around. Not only that, QwikiWiki is open source, requires no prior wiki experience, no advanced Unix skills, and never needs a database! If you're new to wikis and looking for a place to start, QwikiWiki's emphasis on simplicity and...
2
1789
by: Bob Greschke | last post by:
Does Text.delete(0.0, END) delete all of the tags too? Everything says it does not delete marks, but nothing about tags. Thanks! Bob
1
849
by: Ray | last post by:
Hello all, I am attempting to delete multiple rows from multiple tables as follows: DELETE FROM attachments,responses,response_lines WHERE attachments.id IN(2,7,11) AND responses.attachment_id=attachments.id AND response_lines.response_id=responses.id The error message it returns is:
4
6434
by: Li Weng | last post by:
Hi, I have two questions: 1) If there are more than one attachments, can I still use urn:schema:httpmail:attachmentfilename to get the file names? How? Or I need to use X-MS-ENUMATTS method? 2) After I get the filenames of the attachments, how do I download them to a local folder? Thanks in advance.
1
451
by: Karen Grube | last post by:
Hi! I hate to bother you all with this, but I don't know how best to approach a particular task. Here's the deal: Once a month I personally (that is, in my own personal inbox on my company's email server) receive an email from one of our vendors to which is attached a text file, a comma-delimited data file containing the details of our monthly
16
17011
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
16
3252
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will not print in the username or email amddress of the person doing the download - which I am collecting from a form on the previous page. I can get the name and email address to print out normally, just not into the email sending body. I have...
3
2403
by: Mufasa | last post by:
Does anybody have any code that would go out to an e-mail account (I'm using g-mail), get the e-mails and if there are any attachments, get those and save them on the local hard drive? I don't need a fancy user interface, I just need the guts of this. I want a program that runs in the background that I could then have just populating the hard drive with the attachments. TIA - Jeff.
4
9111
by: Seguros Catatumbo | last post by:
Hi guys, i am having trouble deleting a file after sending an email. The file is in use. Here's the code: String texto = "Test"; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(); System.Net.Mail.MailMessage correo = new
0
9343
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.