How to delete and download attachments? | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| |
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. - <cfparam name="form.confirmed" default="0">
-
-
<cfquery name="attachment" datasource="CustomerSupport">
-
SELECT fk_ticketID,description,path
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
-
<form method="post">
-
<cfoutput query="ticket">
-
<input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
-
</cfoutput>
-
<cfoutput query="attachment">
-
<input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
-
</cfoutput>
-
-
<cfoutput query="attachment">
-
#description#
-
<a href="attachments/#path#" target="_blank" >view</a>
-
<br>
-
<cfif form.confirmed EQ 1>
-
<cflock timeout="60">
-
<cffile action="delete"
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
-
</cflock>
-
</cfif>
-
<input type="hidden" name="confirmed" value="1">
-
<input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
-
<input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
-
</cfoutput>
-
</form>
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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 - <cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
an i think i figured out the download, just not sure what to put for destination. but here is what i had come up with for the download part. - <cflock timeout="60">
-
<cffile action="copy"
-
source="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#" destination="">
-
</cflock>
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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? - <cfif form.confirmed EQ 1>
-
-
<cflock timeout="60">
-
<cffile action="delete"
-
-
<cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
-
</cflock>
-
</cfif>
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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? - <cfcontent
-
file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#"
-
deleteFile = "no">
an the delete is working beautifully. But i was wondering if there was a way that after they deleted one a message would appear saying it had been deleted an also show that the file didn't exist anymore. Because right now when i delete it still shows the file until i click refresh.
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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. - <form method="post">
-
<table style="100%" class="ticketlist">
-
<col style="width:10%;" />
-
<col style="width:3%;" />
-
<col style="width:3%;" />
-
<thead>
-
<tr class="attachment" >
-
<th>Attachment</th>
-
<th>View</th>
-
<th>Download</th>
-
</tr>
-
<thead>
-
<tr>
-
<td >
-
<cfoutput query="attachment">
-
#description#
-
</td>
-
<td align="center">
-
<a href="attachments/#path#" target="_blank" >view</a>
-
<br>
-
</td>
-
<td>
-
-
<cfif form.confirmed EQ 1>
-
<cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
<cflock timeout="60">
-
<cffile action="delete"
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
-
</cflock>
-
</cfif>
-
<input type="hidden" name="confirmed" value="1">
-
<input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
-
<input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
-
-
</td>
-
<td>
-
-
</td></cfoutput>
-
-
</tr>
-
</table>
-
</form>
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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. -
<table style="100%" class="ticketlist">
-
<col style="width:10%;" />
-
<col style="width:3%;" />
-
<col style="width:3%;" />
-
<thead>
-
<tr class="attachment" >
-
<th>Attachment</th>
-
<th>View</th>
-
<th>Download</th>
-
</tr>
-
<thead>
-
<tr>
-
<td >
-
<cfif form.confirmed EQ 1>
-
<cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
<cflock timeout="60">
-
<cffile action="delete"
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
-
</cflock>
-
</cfif>
-
<cfoutput query="attachment">
-
#description#
-
</td>
-
<td align="center">
-
<a href="attachments/#path#" target="_blank" >view</a>
-
<br>
-
</td>
-
<td>
-
</td>
-
-
-
<input type="hidden" name="confirmed" value="1">
-
<input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
-
<input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
-
-
</td>
-
<td>
-
-
</td></cfoutput>
-
-
</tr>
-
</table>
-
</form>
Also, when i clicked delete it had an issue becuase it was not wrapped around the cfoutput query="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
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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. - <html>
-
<head>
-
<title>Prevoiusly Submitted Attachments</title>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
-
</style>
-
<cfparam name="form.confirmed" default="0">
-
-
<cfquery name="attachment" datasource="CustomerSupport">
-
SELECT fk_ticketID,description,path
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
-
<cfquery name="ticket" datasource="CustomerSupport">
-
SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
-
FROM
-
dbo.tbl_CS_ticketMaster
-
WHERE pk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
<cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
<cflock timeout="60">
-
<cffile action="delete"
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
-
</cflock>
-
-
<script>
-
function confirmDelete(delUrl) {
-
if (confirm("Are you sure you want to delete")) {
-
document.location = delUrl;
-
}
-
}
-
</script>
-
</head>
-
<body>
-
<form method="post">
-
<cfoutput query="ticket">
-
<input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
-
</cfoutput>
-
<cfoutput query="attachment">
-
<input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
-
</cfoutput>
-
<table class="title">
-
<thead>
-
<tr>
-
<th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
-
</th>
-
</tr>
-
</thead>
-
</table>
-
-
<table style="100%" class="ticketlist">
-
<col style="width:10%;" />
-
<col style="width:3%;" />
-
<col style="width:3%;" />
-
<thead>
-
<tr class="attachment" >
-
<th>Attachment</th>
-
<th>View</th>
-
<th>Download</th>
-
</tr>
-
<thead>
-
<tr>
-
<td >
-
-
<cfoutput query="attachment">
-
#description#
-
<cfif form.confirmed EQ 1>
-
-
</cfif>
-
</td>
-
<td align="center">
-
<a href="attachments/#path#" target="_blank" >view</a>
-
<br>
-
</td>
-
<td>
-
-
-
<input type="hidden" name="confirmed" value="1">
-
<input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
-
<input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
-
-
</td>
-
<td>
-
-
</td></cfoutput>
-
-
</tr>
-
</table>
-
</form>
-
-
</body>
-
</html>
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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 - <cffile action="delete"
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
here is what i have in full - <html>
-
<head>
-
<title>Prevoiusly Submitted Attachments</title>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<cfparam name="form.confirmed" default="0">
-
-
<cfquery name="attachment" datasource="CustomerSupport">
-
SELECT fk_ticketID,description,path
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
-
<cfquery name="ticket" datasource="CustomerSupport">
-
SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
-
FROM
-
dbo.tbl_CS_ticketMaster
-
WHERE pk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
<cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
<cfif form.confirmed EQ 1>
-
<cflock timeout="60">
-
<cffile action="delete"
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
-
</cflock>
-
</cfif>
-
-
<script>
-
function confirmDelete(delUrl) {
-
if (confirm("Are you sure you want to delete")) {
-
document.location = delUrl;
-
}
-
}
-
</script>
-
</head>
-
<body>
-
<form method="post">
-
<cfoutput query="ticket">
-
<input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
-
</cfoutput>
-
<cfoutput query="attachment">
-
<input type="hidden" name="fk_ticketID" id="fk_ticketID" value="#fk_ticketID#" />
-
</cfoutput>
-
<table class="title">
-
<thead>
-
<tr>
-
<th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
-
</th>
-
</tr>
-
</thead>
-
</table>
-
-
<table style="100%" class="ticketlist">
-
<col style="width:10%;" />
-
<col style="width:3%;" />
-
<col style="width:3%;" />
-
<thead>
-
<tr class="attachment" >
-
<th>Attachment</th>
-
<th>View</th>
-
<th>Download</th>
-
</tr>
-
<thead>
-
<tr>
-
<td >
-
-
<cfoutput query="attachment">
-
#description#
-
-
-
-
</td>
-
<td align="center">
-
<a href="attachments/#path#" target="_blank" >view</a>
-
<br>
-
</td>
-
<td>
-
-
-
<input type="hidden" name="confirmed" value="1">
-
<input type="hidden" name="fk_ticketID" value="#fk_ticketID#">
-
<input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
-
-
</td>
-
<td>
-
-
</td></cfoutput>
-
-
</tr>
-
</table>
-
</form>
-
-
</body>
-
</html>
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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?
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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?
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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?
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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?
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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.
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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. - <cfquery name="getattachment" dbtype="query" >
-
SELECT *
-
FROM attachment
-
WHERE pk_attachID=<cfqueryparam value="#form.attachID#"
-
cfsqltype="cf_sql_char" maxLength="20">
-
</cfquery>
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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? - <cfparam name="form.confirmed" default="0">
-
-
-
-
<cfquery name="ticket" datasource="CustomerSupport">
-
SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
-
FROM
-
dbo.tbl_CS_ticketMaster
-
WHERE pk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
<!---<cfquery name="attachment" datasource="CustomerSupport">
-
SELECT pk_attachID,fk_ticketID,description,path
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>--->
-
-
<cfquery name="attachment" datasource="CustomerSupport">
-
SELECT pk_attachID,fk_ticketID,description,path
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
-
<cfif form.confirmed EQ 1>
-
<cfquery name="getattachment" dbtype="query" >
-
SELECT *
-
FROM attachment
-
WHERE pk_attachID=<cfqueryparam value="#form.pk_attachID#"
-
cfsqltype="cf_sql_char" maxLength="20">
-
</cfquery>
-
-
<cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE pk_attachID = #URL.pk_ticketID#
-
</cfquery>
-
<cflock timeout="60">
-
<cffile action="delete"
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#">
-
</cflock>
-
</cfif>
-
-
<script>
-
function confirmDelete(delUrl) {
-
if (confirm("Are you sure you want to delete")) {
-
document.location = delUrl;
-
}
-
}
-
</script>
-
</head>
-
<body>
-
<form method="post">
-
<cfoutput query="ticket">
-
<input type="hidden" name="pk_ticketID" id="pk_ticketID" value="#pk_ticketID#" />
-
</cfoutput>
-
<cfoutput query="attachment">
-
<input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
-
</cfoutput>
-
<table class="title">
-
<thead>
-
<tr>
-
<th>Previously Submitted Attachments to ticket <cfoutput>#pk_ticketID#</cfoutput>
-
</th>
-
</tr>
-
</thead>
-
</table>
-
-
<table style="100%" class="ticketlist">
-
<col style="width:10%;" />
-
<col style="width:3%;" />
-
<col style="width:3%;" />
-
<thead>
-
<tr class="attachment" >
-
<th>Attachment</th>
-
<th>View</th>
-
<th>Download</th>
-
</tr>
-
<thead>
-
<tr>
-
<td >
-
-
<cfoutput query="attachment">
-
#description#
-
-
-
-
</td>
-
<td align="center">
-
<a href="attachments/#path#" target="_blank" >view</a>
-
<br>
-
</td>
-
<td>
-
-
-
<input type="hidden" name="confirmed" value="1">
-
<input type="hidden" name="pk_attachID" value="#pk_attachID#">
-
<input type="submit" value="delete" onClick="return confirm('Are you sure you want to delete?')">
-
-
</td>
-
<td>
-
<!---<cfcontent
-
file = "C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#path#"
-
type="text/html;text/plain;application/x-shockwave-flash;application/msword;image/jpeg; "
-
deleteFile = "no">--->
-
</td></cfoutput>
-
-
</tr>
-
</table>
-
</form>
-
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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. -
<cfoutput query="attachment">
-
<input type="hidden" name="attachID" id="attachID" value="#form.attachID#" />
-
</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.
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: How to delete and download attachments?
The delete query should be matching the attachID: - <cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE pk_attachID = #form.pk_attachID#
-
</cfquery>
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: How to delete and download attachments? Quote:
Originally Posted by acoder The delete query should be matching the attachID: - <cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE pk_attachID = #form.pk_attachID#
-
</cfquery>
Hey Acoder,
I did this - <cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE attachID = #URL.pk_ticketID#
-
</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
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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? - <cfparam name="form.confirmed" default="0">
-
<cfquery name="ticket" datasource="CustomerSupport">
-
SELECT pk_ticketID,status,title,date_last_modified,date_submitted,customer_company
-
FROM
-
dbo.tbl_CS_ticketMaster
-
WHERE pk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
<cfquery name="attachment" datasource="CustomerSupport">
-
SELECT pk_attachID,fk_ticketID,description,path
-
FROM dbo.tbl_CS_attachments
-
WHERE fk_ticketID = #URL.pk_ticketID#
-
</cfquery>
-
-
-
<cfif form.confirmed EQ 1>
-
<cfquery name="getattachment" dbtype="query" >
-
SELECT *
-
FROM attachment
-
WHERE attachID=<cfqueryparam value="#form.pk_attachID#"
-
cfsqltype="cf_sql_char" maxLength="120">
-
</cfquery>
-
-
<cfquery name="deleteattachment" datasource="CustomerSupport">
-
DELETE
-
FROM dbo.tbl_CS_attachments
-
WHERE pk_attachID = #URL.pk_ticketID#
-
</cfquery>
-
<cflock timeout="60">
-
<cffile action="delete"
-
file="C:\Inetpub\Development\WWWRoot\RachelB\footprints\form\attachments\#getattachment.path#">
-
</cflock>
-
</cfif>
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: How to delete and download attachments?
In the getattachment query, you also need to use pk_attachID: - <cfquery name="getattachment" dbtype="query" >
-
SELECT *
-
FROM attachment
-
WHERE pk_attachID=...
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: How to delete and download attachments? Quote:
Originally Posted by acoder In the getattachment query, you also need to use pk_attachID: - <cfquery name="getattachment" dbtype="query" >
-
SELECT *
-
FROM attachment
-
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.
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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 - Error processing CFFILE
-
-
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
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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.
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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
| | | 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.
Thank you,
Rach
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | 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.
|  | | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|