Solved

Display and Upload various file types

Posted on 2006-10-25
5
211 Views
Last Modified: 2013-12-24
I have an application that allows an admin user to upload a file. Users can log in and view the upload file.

My issue is that as of now, only word documents will work. The admin needs to be able to upload Excel, .PDF's and word documents. Is there anyway I can make that happen?

Here is my code:

Upload and Insert Page
----------------------------
<cfif IsDefined("FORM.addDoc")>
  <cffile action="upload"
            destination="C:\somepath\docs\uploadDocs\"
            nameConflict="overwrite"
            fileField="Form.doc">
            
  <!---QUERY: Update Pic--->
<cfquery datasource="DSN" name="addDocuments">
INSERT INTO dbo.documents(
docName,
doc
)
VALUES (
'#FORM.docName#',
'#CFFILE.ServerFile#'

)
  </cfquery>
<cflocation url="viewDocsAdmin.cfm" addtoken="no">
</cfif>

<cfform name="picUpdateForm" id="picUpdateForm" method="post" action=""  enctype="multipart/form-data">  
  <table width="500" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Document Name: <br />
      <input name="docName" type="text" id="docName" size="50" /></td>
    </tr>
    <tr>
      <td><label>File<br />
            <cfinput
                  name="doc" type="file"
                  size="50">
      </label></td>
    </tr>
    <tr>
      <td><label>
        <cfinput name="addDoc" type="submit" value="Add Document" id="addDoc">
      </label></td>
    </tr>
  </table>
</cfform>



Document Display Page
-----------------------------
<cfquery name="viewDoc" datasource="DSN">
SELECT
docID,
doc
FROM   dbo.documents
WHERE docID= '#url.docID#'
</cfquery>

<cfheader name="Content-Disposition" value="inline; filename=#viewDoc.doc#;">  
          <cfcontent type="application/msword" file="docs\uploadDocs\#trim(viewDoc.doc)#" deletefile="No" reset="yes">  

-----------------------------------

As you can see, in the cfcontent type tag, I have application/msword specified. Is there anyway to have the cfcontent tag open the type of file upload?

Thanks.


0
Comment
Question by:meechp123
  • 3
  • 2
5 Comments
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17812425
will "FORM.docName" always contain the file extention/type?

example:

myMsWordDoc.doc
myMsExcelDoc.xsl
anotherfile.doc
anAdobeDoc.pdf

0
 

Author Comment

by:meechp123
ID: 17812459
What's up trail!

Yes. The filename with the extension gets inserted into the database and the file resides in a folder.

Is that what you're asking?
0
 
LVL 20

Accepted Solution

by:
trailblazzyr55 earned 500 total points
ID: 17812530
Yup, how's it going?

in that case give this a try...

Document Display Page
-----------------------------
<cfquery name="viewDoc" datasource="DSN">
SELECT docID, doc, docName
FROM   dbo.documents
WHERE docID= '#url.docID#'
</cfquery>

<cfscript>
switch(listlast(viewDoc.docName,'.')){
      case "doc": docType = "application/msword"; break;
      case "xls": docType = "application/msexcel"; break;
      case "pdf": docType = "application/pdf"; break;
      default:    docType = "text/html";
}
</cfscript>

<cfheader name="Content-Disposition" value="inline; filename=#viewDoc.doc#;">  
<cfcontent type="#docType#" file="docs\uploadDocs\#trim(viewDoc.doc)#" deletefile="No" reset="yes">

-----------------------------------
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17812571
you can then add cases for different file types too by checking for the file type be it .doc,.pdf,.xls,.txt,.etc....

also on the <cfcontent> tag when you use the "file" attribute, I don't believe the "reset" attribute is ever used then... you could probably remove that "reset" attrib....

0
 

Author Comment

by:meechp123
ID: 17813099
Thanks again! Here is the code if anyone else needs the full docdisplay.cfm file. I added jpg's and gif's.

<cfquery name="viewDoc" datasource="DSN">
SELECT
docID,
doc
FROM   dbo.documents
WHERE docID= '#url.docID#'
</cfquery>

<cfscript>
switch(listlast(viewDoc.doc,'.')){
     case "doc": docType = "application/msword"; break;
     case "xls": docType = "application/msexcel"; break;
     case "pdf": docType = "application/pdf"; break;
     case "jpg": docType = "image/jpeg"; break;
     case "gif": docType = "image/gif"; break;
     default:    docType = "text/html";
}
</cfscript>


<cfheader name="Content-Disposition" value="inline; filename=#viewDoc.doc#;">  
          <cfcontent type="#docType#" file="docs\uploadDocs\#trim(viewDoc.doc)#" deletefile="No">  
             
             
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now