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

Discussion in 'ASP .Net' started by Mark Sandfox, May 10, 2004.

  1. Mark Sandfox

    Mark Sandfox Guest

    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.
    Mark Sandfox, May 10, 2004
    #1
    1. Advertising

  2. 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.
    >
    >
    Jason DeFontes, May 11, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2liQW5kZWxh?=

    <INPUT type="file" runat="server" - attach to email

    =?Utf-8?B?U2liQW5kZWxh?=, Jul 31, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    823
    Lau Lei Cheong
    Aug 2, 2004
  2. yoshra
    Replies:
    0
    Views:
    578
    yoshra
    May 8, 2005
  3. =?Utf-8?B?SmFpbWUgU3R1YXJkbw==?=

    Difference between <asp:textbox> and <input runat="server">

    =?Utf-8?B?SmFpbWUgU3R1YXJkbw==?=, Oct 7, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    7,423
    Mr Newbie
    Oct 7, 2005
  4. Replies:
    5
    Views:
    207
  5. Patrick May

    iphoto parsing

    Patrick May, Jan 8, 2006, in forum: Ruby
    Replies:
    3
    Views:
    82
    Michael Fellinger
    Jan 10, 2006
Loading...

Share This Page