Closed Thread Icon

Topic awaiting preservation: Using input type=file (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8293" title="Pages that link to Topic awaiting preservation: Using input type=file (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Using input type=file <span class="small">(Page 1 of 1)</span>\

 
Yossi Admon
Bipolar (III) Inmate

From: Israel
Insane since: Nov 2001

posted posted 09-01-2002 19:51

Hi.
I'm using the html tag <input type="file" ...> to upload files.
Can I set the type of the files to upload using the "Choose file" window?

Example:
I want to upload zip files only therefore I want to filter only zip files and directories to be seen.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 09-01-2002 19:59

im not sure, but i dont think that's possible without a server side scripting language.

with sss you could determine the type of the file after it has been uploaded.
im using such a script here: www.embege.com/yearbook
which only accepts gifs

tell me if you are interested.

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 09-01-2002 21:38

There's an attribute called "accept" that lets you specify the mime types which the browser should accept for that field. I don't know in which browsers this will or won't work though.

This is how it should look like in your case:

<input type="file" accept="application/zip" />

You can find a (German) overview of various mime types here:
http://selfhtml.teamone.de/diverses/mimetypen.htm#uebersicht

kuckus (cell #282)

Yossi Admon
Bipolar (III) Inmate

From: Israel
Insane since: Nov 2001

posted posted 09-02-2002 07:53

I read about the accept attribute, this is exactly what I need but it's not working.
I have tryied it on NS6 and IE5.5

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 09-02-2002 10:01

As the support for accept-type is so unsure in browsers, i'd go for a small javascript that checks the extension before submitting the form, like this:

code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>X-tension-tester</title>
<script language="JavaScript" type="text/javascript">
//by DmS at [url=http://www.dmsproject.com/]http://www.dmsproject.com/[/url]
function checkIt(){
//picks the complete path for the file to be uploadend
var file = document.forms["uploader"].upFile.value;
alert(file);
//checks if the string ends with ".zip"
regX = new RegExp(".zip$");
//if it's true submit the form and upload,
// otherwise prompt with good message ;-)
if(regX.test(file)){
alert("zippwedido... uploading...");
return true;
}else{
alert("nope, only .zip files...");
return false;
}
}


</script>
</head>

<body>
<form action="#" enctype="multipart/form-data" name="uploader" id="uploader" onsubmit="return checkIt()">
<input type="file" name="upFile">
<input type="submit" name="submit" value="submit"">
</form>


</body>
</html>


Be sure that you match this with a check on the recieving server since this won't work if you disable javascript.
/Dan

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

« BackwardsOnwards »

Show Forum Drop Down Menu