Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

cffile accept WordPerfect documents???

Posted on 2004-10-14
8
Medium Priority
?
320 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 500 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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 

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
 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
What You Need to Know when Searching for a Webhost Provider
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

885 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