Team LiB
Previous Section Next Section

Creating the Form

Start out by creating a one-field form. You can create a form to upload as many files as you like, after you get this sequence to work with one file.

  1. Open a new file in your text editor and type the following HTML:

    <HTML>
    <HEAD>
    <TITLE>Upload a File</TITLE>
    </HEAD>
    <BODY>
    <H1>Upload a File</H1>
    
  2. Begin your form. Assume that the method is POST and the action is a script called do_upload.php. Because you'll be sending more than just text, use the ENCTYPE attribute.

    <FORM METHOD="POST" ACTION=" do_upload.php" ENCTYPE="multipart/form-data">
    
  3. Create an input field for the file with a text label. Assume that you'll be uploading an image file, and name the input field img1:

    <p><strong>File to Upload:</strong><br>
    <INPUT TYPE="file" NAME="img1" SIZE="30"></P>
    
    
    
    Note 

    The TYPE="file" attribute in the form field will display an input field with a Browse button. The Browse button launches a file manager through which you select the file to upload.

  4. Add a submit button, and then close your form and add some more HTML so that the document is valid:

    <P><INPUT TYPE="submit" NAME="submit" VALUE="Upload File"></P>
    </FORM>
    </BODY>
    </HTML>
    
  5. Save the file with the name upload_form.html, and place this file in the document root of your web server.

  6. Open your web browser and type http://127.0.0.1/upload_form.html.

    Click To expand

In the next section, you create the script that handles the file upload.


Team LiB
Previous Section Next Section