Solved

cffile accept WordPerfect documents???

Posted on 2004-10-14
8
311 Views
Last Modified: 2013-12-24
I've got a file upload option that will only accept text files (text/plain, text/richtext, application/rtf, application/wordperfect, application/pdf, application/macwriteii, application/msword).
No matter what I put in for danged WordPerfect, this file type is not accepted.
I've scoured the web and have found no solution.
Hence... I am turning to the experts!
Any insight will be much appreciated.
0
Comment
Question by:jlynn_tn
  • 4
  • 3
8 Comments
 
LVL 7

Accepted Solution

by:
black0ps earned 125 total points
ID: 12313808
This is the info I found on mime type for WordPerfect:
application/wordperfectd       wpd
application/wordperfect        wp wpd
application/wordperfect5.1     wp5
application/wordperfect6.1    wp6
Reference: http://webmaster.iu.edu/mimetypes/

WordPerfect files use extentions wpd,wp,wp5,wp6. Instead of doing a server side validation of the file extension, do a client side javascript or do a server side validation for the extension:

Something like:
<script language="Javascript">
<!--
// x1 = name of form
// x2 = name of image field
// x3 = quote enclosed list of acceptable file types: ".jpg",".jpeg",".gif"
function correctFormats(x1,x2,x3,x4) {
      v2 = document.forms[x1].elements[x2].value.toLowerCase();
      formats = x3.split(",");
      disFormats = "";
      for (j=0;j<formats.length;j++) {
            disFormats = disFormats+"  "+(j+1)+" "+formats[j]+"\r";
      }
      submitform = false;
      if (v2 != '') {
            for (i=0;i<formats.length;i++) {
                  x4 = formats[i];
                  if (v2.indexOf(formats[i]) == -1) {
                        submitform = false;
                  }
                  else {
                        submitform = true;
                        break;
                  }
            }
      }
      else {
            submitform = true;
      }
      if (!submitform) {
            alert("The file you selected for upload was the incorrect format.\r\rAllowed file types include:\r"+disFormats+"Please ensure the file you are uploading is one of these file types.");
            }
      return submitform;
}

//-->
</script>

<cfset formats = "correctFormats('Place','image','.jpg,.jpeg,.gif,.bmp,.png','#Right(Photo.Image,3)#'); return submitform;">
<cfform name="Photo" method="post" action="index.cfm?FuseAction=Details&#Client.URLToken#" enctype="multipart/form-data" onsubmit="#formats#">
 </cfform>
0
 
LVL 1

Expert Comment

by:hiranmaya
ID: 12315880
test2.cfm:

<CFIF isDefined("form.fieldNames")>
<cffile action="upload" filefield="ul_path"       destination= "c:\temp"
                  nameconflict="overwrite">
</cfif>


<form action="test2.cfm" method="post" name="dataForm" enctype="multipart/form-data" id="dataForm">
<input type="file" name="ul_path" id="ul_path">
<input type="submit" value="Submit">
</form>
0
 

Author Comment

by:jlynn_tn
ID: 12320877
OK - blackOps, you recommend client-side validation with javascript with a 'catch' on the server?

I already do validation on the form fields - hadn't thought of also looking at the uploaded file extensions - your javascript may do the trick. I'll try incorporating that into what I'm using but I'm a bit of a neophyte on javascripting...

In your referenced javascript, I would imagine for my purposes, the X2 would be the name of the form file field - yes? and, what is the X4 argument?

Note that I did try adding all the various wordperfect designations and none of them worked a'tall.
0
 

Author Comment

by:jlynn_tn
ID: 12321437
hiranmaya - was this a response to *this* question? I don't understand...
My intent is to filter out all files other than text, word processor, and pdf files.
My original query was with regards to cffile 'accept' - which won't accept WordPerfect files. I don't see how your solution will fix this - am I missing something?
Thanks tho, for taking time to reply!
jLynn
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 7

Expert Comment

by:black0ps
ID: 12321564
x1 is the name of the form // for reference to the field
x2 is the name of the upload field
x3 is the list of extensions you want to accept.
  It needs to be called with an onSubmit call like this:

<cfset formats = "correctFormats('Place','image','.txt,.rtf,.doc,.wpd,.wp,.wp5,.wp6,.pdf'); return submitform;">

<cfform name="Photo" action="index.cfm" enctype="multipart/form-data" onsubmit="#formats#">

When I was writing this code originally, x4 was going to be the extension in the file field. You can remove it, as it is no longer valid. The reason why I decided to go with client-side is because I could never get the mime type thing to work properly. I found by using client-side, that while a very small population do not have JS enabled, most people have it and it works well. It also means that the file doesn't get uploaded, then validated. It validates before it uploads.
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12321573
So in cfset for formats, change out "Place" with the name of your form and change out "image" with the name of your field. They are case sensitive as well.

-- Ian
0
 

Author Comment

by:jlynn_tn
ID: 12324181
blackOps
All good, sound reasons for doing the client-side validation!
One question before I begin implementation... I currently use the 'onsubmit' for javascript validation of required fields - would I then move this validation into the 'correctFormats' function?
Again, thanks for this... will be helpful not only for this form but for the future as well!
jLynn
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12324504
You can do it in two ways:
1. Adding the correctFormat() function to the end of your client-side form validation function

or

2. Use ColdFusion's built-in form validation using <cfform> and <cfinput>. I find those tags very powerful and time savers. ColdFusion will take whatever onsubmit function is in the cfform tag and insert into the built-in Javascript functions used for form validation.

Option 2 is my recommendation, but may mean a bit more work.
0

Featured Post

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
remove Handler and Add Handler for one file 3 31
Help Fix A 403 error 13 94
Website being blocked? 3 114
AWS Advice on using WHM/cPanel 1 59
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…
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…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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