468,769 Members | 2,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,769 developers. It's quick & easy.

<input id="iPhoto" type="file" size="20" runat="server">

Is there a way to restrict the user to only selecting and sending either a
..gif or .jpg. Everything I have read says this option can not be done by
design (security reasons). I find that irronic as this is the reason
(security) that I want to restrict their selection.

Any help on this one will be greatly appreciated.

The page is using ASP.NET.
Nov 18 '05 #1
1 2737
You can sort of fudge it with javascript, but you need to back this up
by checking the mime type of the uploaded file and throwing an error if
it's not what you expect:

<html>
<head>
<script>
function checkFile()
{
var path = document.forms[0].myImage.value;
var ext = path.substring(path.length - 4, path.length).toLowerCase();
if (ext != ".jpg" && ext != ".gif")
{
alert("You must choose an image file!");
document.forms[0].reset();
}
}
</script>
</head>
<body>
<form>
<input type="file" name="myImage" onchange="checkFile();">
</form>
</body>
</html>

-Jason

Mark Sandfox wrote:
Is there a way to restrict the user to only selecting and sending either a
.gif or .jpg. Everything I have read says this option can not be done by
design (security reasons). I find that irronic as this is the reason
(security) that I want to restrict their selection.

Any help on this one will be greatly appreciated.

The page is using ASP.NET.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.