So I'm busy making my own theme in WordPress and am busy with the settings page:
I'm preparing the handler that will save the file to the media library. This is the handler code:
function handle_logo_upload() {
if ( !function_exists( 'wp_handle_upload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
}
$upload_overrides = array( 'test_form' => false );
$uploadedfile = $_FILES['upload_logo']['name'];
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
print_r($movefile);
wp_die();
if ( $movefile ) {
$wp_filetype = $movefile['type'];
$filename = $movefile['file'];
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
'post_mime_type' => $wp_filetype,
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename);
echo '<br>';
//return $attach_id;
//var_dump($movefile);
print_r($movefile);
//wp_die('end');
} else {
return 'fail';
}
}
The file name is being grabbed properly but when I do a print_r
on $movefile
, I get the following error: Array ( [error] => Specified file failed upload test. )
No file is added to the media library.
What do I need to do to my code for it to pass the test?
Here is a screenshot of the settings page for my theme: http://pasteboard.co/yFck7LW.png