check clientside file size

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yonthebeach@googlemail.com

    #1

    check clientside file size

    hi,

    i have an upload mechanism on my website and want to check the filesize
    on the client size. is this possible?

    thanks
    yavuz bogazci

  • Rik

    #2
    Re: check clientside file size

    yonthebeach@goo glemail.com wrote:[color=blue]
    > hi,
    >
    > i have an upload mechanism on my website and want to check the
    > filesize on the client size. is this possible?[/color]


    Not with PHP, which doesn't work client sided.
    What is possible:

    "Example 38-1. File Upload Form

    A file upload screen can be built by creating a special form which looks
    something like this:

    <!-- The data encoding type, enctype, MUST be specified as below -->
    <form enctype="multip art/form-data" action="__URL__ " method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_ SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
    </form>

    The __URL__ in the above example should be replaced, and point to a PHP
    file.

    The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file
    input field, and its value is the maximum filesize accepted. This is an
    advisory to the browser, PHP also checks it. Fooling this setting on the
    browser side is quite easy, so never rely on files with a greater size being
    blocked by this feature. The PHP settings for maximum-size, however, cannot
    be fooled. This form element should always be used as it saves users the
    trouble of waiting for a big file being transferred only to find that it was
    too big and the transfer failed."

    So, always check is server-sided. You can hint to the user what the maximum
    allowed size is, they can choose to ignore it.

    Grtz,
    --
    Rik Wasmus


    Comment

    • Alvaro G. Vicario

      #3
      Re: check clientside file size

      *** yonthebeach@goo glemail.com escribió/wrote (23 Jun 2006 04:51:41 -0700):[color=blue]
      > i have an upload mechanism on my website and want to check the filesize
      > on the client size. is this possible?[/color]

      In general, it's impossible to do so with pure HTML. You'd need a signed
      Java applet or similar complicate solutions. Also, I believe you can also
      do it with JavaScript, but never tested it myself.



      --
      -+ Álvaro G. Vicario - Burgos, Spain
      ++ http://bits.demogracia.com es mi sitio para programadores web
      +- http://www.demogracia.com es mi web de humor libre de cloro
      --

      Comment

      Working...