WordPress.org

Ready to get started?Download WordPress

Forums

wp_handle_upload() only returns file name (1 post)

  1. niklasbr
    Member
    Posted 2 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic