5.8. File Uploads

We haven't yet covered one type of input-uploading files. You can use the file upload feature of PHP to upload images or related materials, for example. Because the browser needs to do a little bit more than just send a POST with the relevant data, you need to use a specially crafted form for file uploads. Here is an example of such a special form:

<form enctype="multipart/form-data" action="handle_img.php" method="post">
     <input type="hidden" name="MAX_FILE_SIZE" value="16000" />
     Send this file: <input name="book_image" type="file" /><br />
     <input type="submit" value="Upload" />
</form>

The differences between file upload forms and normal forms are bold in the code listing. First, an enctype attribute, included in the form ...

Get PHP 5 Power Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.