I have CFMX installed running on a windows machine.
I have a section on the site where users can view the
files that are attached to a log.
I've called this file showAttachments.cfm
Here is the code:
showattachments.cfm
-------------------
<cfquery name="showAttachments" datasource="db">
select * from attachments where logID = '#url.id#'
</cfquery>
<table width="100%" height="115" cellpadding="0"
cellspacing="0">
<cfloop query="showAttachments">
<tr>
<td valign="top">
<a href="" > window.open('viewattachment.cfm?id=#fileID#&filename=#fileName#',
'Document',
'top=10,left=10,height=500,width=600,resizable=Yes,scrollbars=Yes')">#fileName#</a>
</td>
</tr>
</cfloop>
</table>
Clicking on the ahref link opens up
viewattachment.cfm.
Here is the code.
viewattachment.cfm
-------------------
<!--- Code starts here --->
<cfquery name="getAttachmentDetails" datasource="db">
select * from attachments where logID = '#url.id#'
and fileName = '#url.filename#'
</cfquery>
<cftry>
<cfif getAttachmentDetails.recordcount gt 0>
<cfset fName = getAttachmentDetails.FileName>
<CFX_GETIMAGE
DATASOURCE="db"
USER=""
PASSWORD=""
SQL="select Contents FROM attachment WHERE logID =
'#url.id#' and fileName = '#url.filename#'"
OUTPUT="E:\inetpub\wwwroot\FileUploads\#fName#">
<cfelse>
<cfset fName = url.filename>
</cfif>
<!---Allowed Mime Types--->
<cfscript>
mimetypes=arraynew(1);
mimetypes[1]="application/msword,application/msword,doc";
mimetypes[2]="application/x-msexcel,xls";
mimetypes[3]="application/pdf,application/pdf,pdf";
mimetypes[4]="text/plain,text/plain,txt";
mimetypes[5]="application/rtf,application/rtf,rtf";
mimetypes[6]="application/text,plain,csv";
mimetypes[7]="image/jpeg,image/jpeg,jpg,image/x-png,image/pjpeg,image/png,image/jfif";
mimetypes[8]="image/gif,image/gif,gif";
mimetypes[9]="application/x-visio,vsd";
mimetypes[10]="application/drafting,drw";
mimetypes[11]="model/vnd.dwf,dwf";
mimetypes[12]="image/x-dwg,dwg";
mimetypes[13]="application/dxf,dxf";
mimetypes[14]="application/x-excel,xls";
mimetypes[15]="application/vnd.ms-excel,xls";
legalextensions="doc,xls,pdf,txt,rtf,csv,gif,jpg,vsd,drw,dwf,dwg,dxf";
mimetype=listgetat(mimetypes[listfindnocase(legalextensions,trim(right(fName,3)))],1);
</cfscript>
<CFHEADER NAME="Content-Type" VALUE="#mimetype#">
<CFHEADER NAME="Content-Disposition" VALUE="inline;
filename=#fName#">
<cfif getAttachmentDetails.recordcount gt 0>
<CFCONTENT TYPE="#mimetype#"
FILE="E:\inetpub\wwwroot\FileUploads\#fName#"
deletefile="yes">
</cfif>
<cfcatch type="any">
<cfoutput><font color="##FF0000">An error has
occurred!.</font></cfoutput><cfabort>
</cfcatch>
</cftry>
<!--- Code ends here --->
The above code works fine. It opens the file inside
the browser window. However I want the file to open
inside its own application. So if the attached file is
a word document, I want it to open in msword. Also,
because this is an intranet/internal application, once
after the document is open, if the user wishes to edit
the document, I want to save the changes automatically
saved back to the database when the user presses the
save button. I hope I am making sense.
Can somebody show me how to do this.
I'll really appreciate your help
Best regards
cfcoder
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]