Uploading Files with Forms and PHP
(Page 1 of 3 )
Timothy shows you how you can accept file uploads with PHP.
Many sites allow users to upload files through an HTML form. While there are many security issues that should be addressed before allowing file uploads, the actual mechanisms to allow this are fairly easy.
The first task is to construct an HTML form as an interface for a user to upload his file:
<form action="upload.php" method="post" enctype="multipart/form-data"> <p>File Upload</p> <label for="file">File</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> |
You've probably noticed two differences from other forms you may have designed: the enctype attribute of the form tag and the type attribute of the input tag. The form element's enctype specifies which content-type to use when submitting information back to the server. The input element's type is used designate the input element as a file select control. You'll also notice when you view the HTML in a browser that you'll also have a "Browse" button, which is part of the file select control.
The viewer will enter the URI of a file in the input field and a copy of the file will be sent to the server when he submits the form. When received, the file is stored temporarily on the server.
Next: PHP Code >>
More Miscellaneous Articles
More By bluephoenix