Set file dialog to only pickup certain file types..

Posted on 2003-03-06
Medium Priority
Last Modified: 2010-04-09
I only want to get zip and rar file type from the file dialog.... ive tried:
<INPUT TYPE="FILE" SIZE="60" NAME="FILE1" accept="application/x-zip-compressed">
              <INPUT TYPE="FILE" SIZE="60" NAME="FILE2" accept="application/zip">

in IE6 and none of these work... I can still pick any file type and all file types are shown....
Question by:simlox
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Expert Comment

ID: 8080258
This is how it suppose to work, but as of now, it is not supported on any of the browsers.

Expert Comment

ID: 8080381
I think it isnt possible to get just zip files from file dialogue. But you can check it in javascript whether the file extention is .zip or not.


Accepted Solution

gator4life earned 150 total points
ID: 8080435
simlox -

As others have stated, you can't yet control what files appear in the Browse... dialog when using <input type="file">.  However, I have provided you here with a short validation script that checks to see what type of file was selected in the file upload control and raises an alert if the filetype is not a .zip or .rar.  It also prevents the user from submitting the form if the file type is not correct, since I am assuming you only want .zip's or .rar's uploaded.  In any case, I hope it helps out in some way! :-)


    <script type="text/javascript">
         function CheckFileFormat(sFilePath, bSubmitPressed) {

              var iLastIndex = sFilePath.lastIndexOf('.', sFilePath.length - 1);
              var sFileExtension = sFilePath.substr(iLastIndex + 1);

              if ((sFileExtension != 'zip') && (sFileExtension != 'rar')) {

                   window.alert('Please select a .zip or .rar file.');

                   if (bSubmitPressed) return false;

    <form name="myForm" action="myPage.html" method="post" onSubmit="JavaScript:  return CheckFileFormat(this.myFile.value, true);">
         <input type="file" name="myFile" onChange="JavaScript: CheckFileFormat(this.value, false);"><br>
         <input type="submit" name="mySubmit" value="Upload File">


(chomp, chomp)
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 53

Expert Comment

ID: 8820498
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

If the user does not know how to close the question, the options are here:



Expert Comment

ID: 8821035
My solution may not have been perfect (better to do this on the server side), but I think my solution deserves at least a B for effort! ;-)

(chomp, chomp)

Author Comment

ID: 8821811
sorry guys. i thought I had accepted this a long while ago.. and gator4life.. thanks again for the answer.. :)

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

762 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