Solved

Display and Upload various file types

Posted on 2006-10-25
5
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

739 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