Solved

cffile accept WordPerfect documents???

Posted on 2004-10-14
8
315 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
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 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