• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

Set file dialog to only pickup certain file types..

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....
0
simlox
Asked:
simlox
1 Solution
 
avnerCommented:
This is how it suppose to work, but as of now, it is not supported on any of the browsers.
0
 
shirjeelCommented:
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.

Shirjeel
0
 
gator4lifeCommented:
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! :-)

<html>

<head>
    <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;
              }
         }
    //-->
    </script>
</head>

<body>
    <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">
    </form>
</body>

</html>

gator4life
(chomp, chomp)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
COBOLdinosaurCommented:
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.

<note>
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.
</note>

If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp


Cd&

0
 
gator4lifeCommented:
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! ;-)

gator4life
(chomp, chomp)
0
 
simloxAuthor Commented:
sorry guys. i thought I had accepted this a long while ago.. and gator4life.. thanks again for the answer.. :)
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now