MAX_FILE_SIZE for HTML forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guile
    New Member
    • Apr 2007
    • 18

    #1

    MAX_FILE_SIZE for HTML forms

    hi,
    I tried to lookup on w3c website for information on the MAX_FILE_SIZE hidden field to restrict the size of file uploads, but couldn't find much. Looked up elsewhere, but generally, couldn't find more than a single line about this. I know that this fails in many browsers, but I'd still like to learn about it. Here are some of my doubts regarding this

    * Is it necessary to include it at the beginning of the form?
    * Does it work for single form containing multiple file upload fields?
    * If I specify a different MAX_FILE_SIZE field before each of the file inputs (for the same form), would it work? If not then what would the final MAX_FILE_SIZE value be? or does that give an error?

    thanks
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    Never heard of it and there is no such thing in html.

    Comment

    • guile
      New Member
      • Apr 2007
      • 18

      #3
      Originally posted by drhowarddrfine
      Never heard of it and there is no such thing in html.
      It is recommended that we include this inside forms containing file uploads.

      <input type="hidden" name="MAX_FILE_ SIZE" value="512000" />

      This limits the size of file that can be uploaded. I mostly use php, and it gives an error if the uploaded file exceeds this value. It must be similar in other scripting languages.

      Comment

      • drhowarddrfine
        Recognized Expert Expert
        • Sep 2006
        • 7434

        #4
        This limits the size of file that can be uploaded.
        It does not. "name" is a name you assign to the input element and nothing else. I googled around and it seems it might be a common name used in PHP for such things but the form's "action" calls a PHP script where, I assume, that name is used to monitor the file size. In any case, HTML and the browser does absolutely nothing with the name except transmit it to the server inside the form.

        Comment

        • epots9
          Recognized Expert Top Contributor
          • May 2007
          • 1352

          #5
          i think this is what he wants
          Code:
          ;;;;;;;;;;;;;;;;
          ; File Uploads ;
          ;;;;;;;;;;;;;;;;
          
          ; Whether to allow HTTP file uploads.
          file_uploads = On
          
          ; Temporary directory for HTTP uploaded files (will use system default if not
          ; specified).
          ;upload_tmp_dir =
          
          ; Maximum allowed size for uploaded files.
          upload_max_filesize = 2M
          edit that in the php.ini file

          i think this is php question more than an HTML...

          Comment

          • ma7erick
            New Member
            • Feb 2009
            • 1

            #6
            Hi. I do not know how but MAX_FILE_SIZE really works. I've just tried it in my form in which PHP handles file uploads. After submitting a form which contains file, which size exceeds MAX_FILE_SIZE value, PHP $_FILES array doesn't comprise any file.

            Could anyone tell me how it works?

            Comment

            • drhowarddrfine
              Recognized Expert Expert
              • Sep 2006
              • 7434

              #7
              This has nothing to do with HTML. Go ask on the PHP board. There is no such thing in HTML.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                Originally posted by drhowarddrfine
                This has nothing to do with HTML. Go ask on the PHP board. There is no such thing in HTML.
                I agree with that.

                MAX_FILE_SIZE is submitted via HTML but is used by PHP.

                Comment

                • sikodelika
                  New Member
                  • Jun 2009
                  • 1

                  #9
                  Its not a html tag, its an form input tag with the name of "MAX_FILE_SIZE" .

                  PHP uses that variable to limit the file upload if its bigger than said amount.

                  Sources:

                  Learn how to check errors, the meaning of various error codes and the usage of the MAX_FILE_SIZE form field.


                  ** Edit **
                  Offensive comments removed.
                  Last edited by NeoPa; Jun 10 '09, 10:09 PM. Reason: Removed offensive comments

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    as it was already stated it is not a HTML-question that belongs to this HTML-forum and therefor it was already suggested to post in the PHP-forum ... and i even wouldn't use that at all since it is just very simple to hack ... and the server has to double-check the uploaded file again to ensure the allowed filesize anyway. so i cannot imagine where this usage would be 'suggested'? ...

                    Comment

                    • drhowarddrfine
                      Recognized Expert Expert
                      • Sep 2006
                      • 7434

                      #11
                      I stand by everything I said before, including the information posted. I may be a 'jackass' and a 'douche' but at least I'm not stupid and uninformed.

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32669

                        #12
                        Originally posted by ma7erick
                        Hi. I do not know how but MAX_FILE_SIZE really works. I've just tried it in my form in which PHP handles file uploads. After submitting a form which contains file, which size exceeds MAX_FILE_SIZE value, PHP $_FILES array doesn't comprise any file.

                        Could anyone tell me how it works?
                        As I welcome you to Bytes, I would like to point you in the general direction of posting in forums (here specifically but generally too).

                        When you have a question it is not appreciated (It is specifically against our rules) that you post it within an existing thread. This is called Thread Hijacking and will tend to upset the current participants.

                        Furthermore, it is good policy if you can, to post your new thread in the relevant forum.

                        I can see you're new at this so I'm not about to throw any infractions at you, but please try to remember this for future usage of the forums.

                        I think it's probably clear by now that you need the PHP forum for this particular question. Good luck.

                        Administrator.

                        Comment

                        • usrhlp
                          New Member
                          • Jun 2010
                          • 2

                          #13
                          I know this is late after the thread has basically died but after finding this listing from a google search i thought i better mention it.

                          It does look as though this is some sort of HTML tag.

                          I have done a simple test using the following code, this code has the MAX_FILE_SIZE within it as a HTML tag, there is no php code on this page.

                          -----FILE UPLOAD CODE-----
                          Code:
                          <form enctype="multipart/form-data" action="moveimage.php" method="POST">
                          <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
                          Choose a file to upload: <input name="uploadedfile" type="file" /><br />
                          <input type="submit" value="Upload File" />
                          </form>
                          --------------------------

                          Here is my PHP code, note how there is NO reference to MAX_FILE_SIZE at all.

                          -----PHP FILE ACCEPT CODE-----
                          Code:
                          <?php
                          $target_path = $target_path . "/" . basename( $_FILES['uploadedfile']['name']);
                          
                          if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
                              echo "The file ". $target_path . " has been uploaded";
                          } else{
                              echo "There was an error uploading the file, please try again!";
                          }
                          
                          ?>
                          The argument MAX_FILE_SIZE is never referenced by any of my PHP code and i do no checks on the file size, yet if i upload a file over 100K it fails........

                          It is as though the form from HTML is not passing the file names / form arguments through to the php file.

                          I just had to post this in case anyone else finds this thread in google and wants some more information like i did.
                          Last edited by Dormilich; Jun 20 '10, 12:19 PM. Reason: Please use [code] tags when posting code

                          Comment

                          • drhowarddrfine
                            Recognized Expert Expert
                            • Sep 2006
                            • 7434

                            #14
                            Because THERE IS NO SUCH THING AS MAX_FILE_SIZE IN HTML. Here is the list of ALL html elements and a link at the top for ALL HTML attributes as published by the W3C.

                            Any further comments remotely implying that there is such a thing in the HTML spec is pure poppycock.

                            Comment

                            • usrhlp
                              New Member
                              • Jun 2010
                              • 2

                              #15
                              Ah, so it's a magical item that doesn't exist but works exactly as expected?

                              could it be built into the browser?

                              Comment

                              Working...