mardi 16 février 2016

file upload in admin panel wordpress

file upload do not work, why? and how can help me? file do not uploaded.

this is settings page

function ag_products_theme_settings_page(){
    ?>
    <div class="wrap">
    <h1>AG Products</h1>
    <form method="post" action="options.php" enctype="multipart/form-data">
        <?php
            settings_fields("section");
            do_settings_sections("theme-options");      
            submit_button(); 
        ?>          
    </form>
    </div>
<?php
}

this is part for displaying logo

function logo_display()
{
    ?>
        <input type="file" name="logo" /> 
        <?php echo get_option('logo');         
        ?>                      
   <?php
}

this is part for uploading logo

function handle_logo_upload()
{
    if(!empty($_FILES["demo-file"]["tmp_name"]))
    {           
        require_once( ABSPATH . 'wp-admin/includes/file.php' );
        $urls = wp_handle_upload($_FILES["logo"], array('test_form' => false));
        $temp = $urls['url'];
        return $temp;
    }       
    return $option;     

}

and this is for register

function ag_products_display_theme_panel_fields()
{
    add_settings_section("section", "All Settings", null, "theme-options");
    add_settings_field("logo", "Logo", "logo_display", "theme-options", "section");  


    register_setting("section", "logo", "handle_logo_upload"); 
}

add_action("admin_init", "ag_products_display_theme_panel_fields");



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire