The m is for maus~. I do what I please. About m~, The Archives and the Lifestream RSS



WordPress Support for Metabox Upload

Sometimes you need to add a custom field metabox which allows the editor to upload a file. Trouble is that the edit form does not have the correct enctype. Here’s the easy way of adding it.

To be able to upload a file, the form you are submitting needs to have the enctype set to multipart/form-data. Strange enough (for security reasons, maybe), the default edit form doesn’t have it. To add it, in your functions.php file:

add_action ( 'admin_head', 'add_multipartToEditForm' );

function add_multipartToEditForm () {
    echo "<script>
        jQuery(document).ready(function() {
	    jQuery("#post").attr("enctype","multipart/form-data");
	});
    </script>";
}