I am trying to make media_handle_upload() work but I keep getting 'Specified file failed upload test.' This is how I am testing it:
<html>
<body>
<form method="post" enctype='multipart/form-data'>
<input type="file" id="file_to_upload" name="dlkimage1" />
<?php
require($_SERVER['DOCUMENT_ROOT'].'/wp/wp-load.php');
require_once( ABSPATH.'wp-admin/includes/file.php' );
if ( isset($_FILES["dlkimage1"]) && !empty($_FILES["dlkimage1"]["tmp_name"]) )
$image_id = media_handle_upload(
$_FILES["dlkimage1"]["tmp_name"], // file
0, // ID of image post
array(), // post data (to overwrite some of the attachment)
array('test_form' => false) );
if ( is_wp_error($image_id) )
echo 'ERROR: ' . $image_id->get_error_message();
else
echo $image_id;
?>
<button class="button" id="updatepreview" type="submit" />Update Preview</button>
</form>
</body>
</html>
What am I missing?