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

  • Thread starter Thread starter Mark Sandfox
  • Start date Start date
M

Mark Sandfox

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.
 
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
 
Back
Top