Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: HTML file upload, size limit  (Read 14409 times)

0 Members and 1 Guest are viewing this topic.

macdad-

    Topic Starter


    Expert

    Thanked: 40
    HTML file upload, size limit
    « on: February 07, 2009, 09:37:19 AM »
    Hey,
    is there a method for the HTML file upload tool, that doesn't upload the file if its over a certain size? or is it only in JS?
    If you dont know DOS, you dont know Windows...

    Thats why Bill Gates created the Windows NT Family.

    kpac

    • Web moderator
    • Moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: HTML file upload, size limit
    « Reply #1 on: February 07, 2009, 11:04:29 AM »
    HTML file upload tool?

    HTML can't actually do the uploading bit, only display the form.
     
    The below is from here: http://www.w3schools.com/php/php_file_upload.asp
    Fairly easy to understand and customise.

    Code: [Select]
    <?php

    if ((($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/pjpeg"))
    && (
    $_FILES["file"]["size"] < 20000))
      {
      if (
    $_FILES["file"]["error"] > 0)
        {
        echo 
    "Error: " $_FILES["file"]["error"] . "<br />";
        }
      else
        {
        echo 
    "Upload: " $_FILES["file"]["name"] . "<br />";
        echo 
    "Type: " $_FILES["file"]["type"] . "<br />";
        echo 
    "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo 
    "Stored in: " $_FILES["file"]["tmp_name"];
        }
      }
    else
      {
      echo 
    "Invalid file";
      }

    ?>


    macdad-

      Topic Starter


      Expert

      Thanked: 40
      Re: HTML file upload, size limit
      « Reply #2 on: February 08, 2009, 03:51:49 PM »
      thanks Kpac, and all this PHP code goes in the html file or a seperate php?
      If you dont know DOS, you dont know Windows...

      Thats why Bill Gates created the Windows NT Family.

      fffreak



        Adviser

      • That's right I am a final fantasy freak.
      • Thanked: 3
        • Yes
        • JSPCRepair
      • Certifications: List
      • Experience: Guru
      • OS: Windows 7
      Re: HTML file upload, size limit
      « Reply #3 on: February 11, 2009, 01:42:02 PM »
      thanks Kpac, and all this PHP code goes in the html file or a seperate php?

      No it doesn't, it all goes in one single PHP or PHTML file...
      Computers are the future, not us. Learn everything you can about them while you still can, soon they will be learning about us... Every bit of advice that I give you is best guess, it is your choice whether or not you listen to it.

      kpac

      • Web moderator
      • Moderator


      • Hacker

      • kpac®
      • Thanked: 184
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 7
      Re: HTML file upload, size limit
      « Reply #4 on: February 11, 2009, 01:57:37 PM »
      thanks Kpac, and all this PHP code goes in the html file or a seperate php?

      Well, you could use your normal HTML page to display the form, and put an action attribute in the form tag:
      <form action="upload.php">...</form>

      macdad-

        Topic Starter


        Expert

        Thanked: 40
        Re: HTML file upload, size limit
        « Reply #5 on: February 11, 2009, 05:18:08 PM »
        so then i would put the could in a seperate php file with "action='upload.php'"?
        If you dont know DOS, you dont know Windows...

        Thats why Bill Gates created the Windows NT Family.

        kpac

        • Web moderator
        • Moderator


        • Hacker

        • kpac®
        • Thanked: 184
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 7
        Re: HTML file upload, size limit
        « Reply #6 on: February 12, 2009, 10:47:52 AM »
        Actually, the above example with only temporarily store the images, unless the tell it to store them.

        This is the HTML file with the form to upload the file:

        Code: [Select]
        <html>
        <body>

        <form action="upload.php" method="post"
        enctype="multipart/form-data">
        <label for="file">Filename:</label>
        <input type="file" name="file" id="file" />
        <br />
        <input type="submit" name="submit" value="Submit" />
        </form>

        </body>
        </html>

        And this is the PHP file, called upload.php, that actually uploads the file and stores in a folder.

        Code: [Select]
        <?php
        if ((($_FILES["file"]["type"] == "image/gif")
        || (
        $_FILES["file"]["type"] == "image/jpeg")
        || (
        $_FILES["file"]["type"] == "image/pjpeg"))
        && (
        $_FILES["file"]["size"] < 20000))
          {
          if (
        $_FILES["file"]["error"] > 0)
            {
            echo 
        "Return Code: " $_FILES["file"]["error"] . "<br />";
            }
          else
            {
            echo 
        "Upload: " $_FILES["file"]["name"] . "<br />";
            echo 
        "Type: " $_FILES["file"]["type"] . "<br />";
            echo 
        "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
            echo 
        "Temp file: " $_FILES["file"]["tmp_name"] . "<br />";

            if (
        file_exists("upload/" $_FILES["file"]["name"]))
              {
              echo 
        $_FILES["file"]["name"] . " already exists. ";
              }
            else
              {
              
        move_uploaded_file($_FILES["file"]["tmp_name"],
              
        "upload/" $_FILES["file"]["name"]);
              echo 
        "Stored in: " "upload/" $_FILES["file"]["name"];
              }
            }
          }
        else
          {
          echo 
        "Invalid file";
          }
        ?>


        Does that explain it well enough? ;)

        macdad-

          Topic Starter


          Expert

          Thanked: 40
          Re: HTML file upload, size limit
          « Reply #7 on: February 12, 2009, 12:19:01 PM »
          yup, Thanks Kpac  :)
          If you dont know DOS, you dont know Windows...

          Thats why Bill Gates created the Windows NT Family.

          kpac

          • Web moderator
          • Moderator


          • Hacker

          • kpac®
          • Thanked: 184
            • Yes
            • Yes
            • Yes
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 7
          Re: HTML file upload, size limit
          « Reply #8 on: February 12, 2009, 12:41:44 PM »
          No problem. :)