By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,749 Members | 1,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,749 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.