8.1. Adding a File Input to the Admin Form

Before you can start processing images with PHP, you must first add the ability to upload images to your administrative form on admin.php. To do this, you' need to add a file upload input to your administrative form.

When using file inputs, you also have to change the enctype, or content type, of the form. By default, HTML forms are set to application/x-www-form-urlencoded. However, this won't work when you're uploading files; instead, you need to set the enctype of the form to multipart/form-data, which can accept files and standard form values.

Modify the form in admin.php to include the code in bold:

<form method="post"
        action="/simple_blog/inc/update.inc.php"
        enctype="multipart/form-data"> <fieldset> ...

Get PHP for Absolute Beginners 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.