Solved

Display and Upload various file types

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
URL redirect 4 56
Google Crawl Errors Producing 404 Errors 4 83
IIS 8.5 2 52
Rebuild awstats from SSH command line on CentOS, from awstats txt files from another server 1 131
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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