CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    72

    <inpu type="file">

    Hi guys

    I want to ask you a very simple question

    Is there a property for the <input type="file"> that allow to set only an extension (for example .doc or .xls) that will appear in the box of the files called by the button browse of the <input type="file">?

    Thanks in advance

  2. #2
    Join Date
    Mar 2006
    Location
    Bratislava, Slovakia
    Posts
    27

    Re: <inpu type="file">

    Quote Originally Posted by elektroman
    Hi guys

    I want to ask you a very simple question

    Is there a property for the <input type="file"> that allow to set only an extension (for example .doc or .xls) that will appear in the box of the files called by the button browse of the <input type="file">?

    Thanks in advance
    Hi the documentation says it could be done via ACCEPT parameter
    HTML Code:
    <input type="file" value="GetTime" accept="image/gif,image/jpeg" />
    But obviously browsers do not support this feature (yet).
    If you want to learn more you could try http://www.cs.tut.fi/~jkorpela/forms/file.html
    ther is also a workaround script for this problem you might find useful..

    Good luck
    Yanco
    You were born an original, don't die a copy..
    Low cost, high quality web design - ASCENT SYSTEMS

  3. #3
    Join Date
    May 2002
    Posts
    10,943

    Re: <inpu type="file">

    I would suggest doing this on the server-side rather than the client-side. You can just read the file extension and accept or reject it.

    Here is a PHP example.
    PHP Code:
    <?php
      $ext 
    strtolower(substr(strrchr($file"."), 1));
      if(
    $ext "doc" || $ext "xls"){
        
    // upload
      
    }
      else{
        echo 
    "Invalid file type.";
      }
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured