Solved

Display and Upload various file types

Posted on 2006-10-25
5
212 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

17 Experts available now in Live!

Get 1:1 Help Now