Solved

cffile accept WordPerfect documents???

Posted on 2004-10-14
8
313 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
Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Troubleshoot mediawiki <-> ActiveDirectory authentication 2 111
Asp.net plan security, reliable, stable 2 109
CFFILE upload help 98 136
System Analysis 5 51
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

20 Experts available now in Live!

Get 1:1 Help Now