wp_handle_upload() only returns file name
-
I am writing an upload function for a theme options page in which I have the following functions called:
register_setting('my-theme-options', 'my-theme-options', 'my_settings_validate'); add_settings_field('header_logotype', __('Upload image'), 'my_setting_header_logotype', 'my-header-options', 'section_general'); function my_setting_header_logotype() { $options = get_option('my-theme-options'); if ($file = $options['header_logotype']) { echo '<img src="' , $file['url'] , '">'; } echo '<input type="file" name="my-theme-options[header_logotype]">'; } function my_settings_validate($input) { if ($_FILES['header_logotype']) { $newinput['header_logotype'] = wp_handle_upload($_FILES['header_logotype'], array('test_form' => false)); return $newinput; } else { return $input; } }
wp_handle_upload() should return an associative array but only returns the file name as a string and no file is saved. What am I doing wrong?
- The topic ‘wp_handle_upload() only returns file name’ is closed to new replies.