Solved

Display and Upload various file types

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

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.
What You Need to Know when Searching for a Webhost Provider
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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