SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Nov 2011
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setting max file size in html

    HTML Code:
    <input type="hidden" name="MAX_FILE_SIZE" value="500" />
    < input type="file" />
    I know that the above code can easily be bypassed and that I require server side checking, but my question is how does the input type="hidden" that sets the max file size get linked with the input type="file" via plain html only. How would this work if you had multiple file upload forms? I thought they might be linked like radio buttons, so that each much share the same name, but I am not sure.

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ShinVe View Post
    [HTML]my question is how does the input type="hidden" that sets the max file size get linked with the input type="file" via plain html only.
    say you have

    Code:
    <input type='file' name='txtUploadFileName' />
    Then the value in the hidden input with name 'MAX_FILE_SIZE' is submitted with the <form> when the submit button is clicked.

    The server then automatically checks if the size of the file exceeds the value of MAX_FILE_SIZE.

    If it does then your $_FILES['txtUploadFileName']['error'] will equal 2.

    If you have multiple file uploads in the one form then all the form's input names have to be named as arrays by appending [] to each name.

    Code:
    <input type='file' name='txtUploadFileName[]' />
    Then loop through all the file names to be uploaded in $_FILES['txtUploadFileName']['tmp_name'] and process them individually using the same process you would use if uploading just a single file per form.

    So with multiple uploads, the first file name will be in $_FILES['txtUploadFileName']['tmp_name'][0]

  3. #3
    SitePoint Addict
    Join Date
    Nov 2011
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't believe I understand your reply. I am wondering how
    Code:
    <input type="hidden" name="MAX_FILE_SIZE" value="500" />
    becomes associated with a given
    Code:
    <input type="file" />
    . Say I have two <input type="file" />'s. Which file inputs's size is limited by this code? Perhaps <input type="hidden" name="MAX_FILE_SIZE" value="500" /> just sets the max_file_size for every element on the form?

    I understand you have to actually verify the file size from the backend, but I am under the impression that <input type="hidden" name="MAX_FILE_SIZE" value="500" /> gives some form of protection in the HTML, even if it is easy to bypass.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by shinve View Post
    perhaps <input type="hidden" name="max_file_size" value="500" /> just sets the max_file_size for every element on the form?
    yes - there is no association with individual fields - the association is with the entire form.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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