Handling File Uploads
Process uploaded files safely using the _FILES superglobal.
PHP File Uploads Overview
PHP handles file uploads through the $_FILES superglobal. The form must use method="POST" and enctype="multipart/form-data".
HTML Upload Form
The HTML form setup for single and multiple file uploads:
<!-- Single file -->
<form method="POST" action="upload.php"
enctype="multipart/form-data">
<input type="file" name="document">
<button>Upload</button>
</form>
<!-- Multiple files -->
<form method="POST" enctype="multipart/form-data">
<input type="file" name="photos[]" multiple>
<button>Upload All</button>
</form>All lessons in this course
- Reading Files with PHP
- Writing and Appending to Files
- Working with Directories
- Handling File Uploads