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>
            <legend><?php echo $legend ?></legend>
            <label>Title
                <input type="text" name="title" maxlength="150"
                    value="<?php echo $title ?>" />
            </label>
            <label>Image
                <input type="file" name="image" />
            </label>
            <label>Entry
                <textarea name="entry" cols="45"
                    rows="10"><?php echo $entry ?></textarea>
            </label>
            <input type="hidden" name="id"
                value="<?php echo $id ?>" />
            <input type="hidden" name="page"
                value="<?php echo $page ?>" />
            <input type="submit" name="submit" value="Save Entry" />
            <input type="submit" name="submit" value="Cancel" />
        </fieldset>
    </form>

Load admin.php in a browser to see the added file input.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.221.144