471,111 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,111 software developers and data experts.

<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 3107
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 Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.