Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am writing a widget plugin; and I want to insert an input tag:<input type="file"> to browse for a pattern in my widget plugin admin panel; but I have problem to save its value(address of the pattern). It seems that <input type="file"> doesn't work in widget plugins. Is it correct? Are there any other ways to browse a file from the admin panel?

here is the input file code in the widget form function:

<fieldset id="customize">
 <label>Browse pattern:</label>
<input type="file" accept="image/*" size="15" id="<?php echo $this->get_field_id('menupattern'); ?>" name="<?php echo $this->get_field_name('menupattern'); ?>" value="<?php echo $instance['menupattern']; ?>" /> 
</fieldset> 

@s_ha_dum, I have been read the link about enctype ; but it wasn't helpful. please note that in the widget plugins I have to send data by the widget form( $instance ) function, and I want to let the user to select a photo from the webserver; not to upload it!

share|improve this question
1  
I don't see why a file input wouldn't work, if you are properly handling form submission. can't really help you any further without seeing some code. –  Milo May 28 '13 at 18:03
1  
Post your code please. Does your form have an enctype? –  s_ha_dum May 28 '13 at 18:25
    
here is the section of the input file code in the widget settings form: <fieldset id="customize"> <p> <label>Browse pattern:</label> <input type="file" accept="image/*" size="15" id="<?php echo $this->get_field_id('menupattern'); ?>" name="<?php echo $this->get_field_name('menupattern'); ?>" value="<?php echo $instance['menupattern']; ?>" /> </p> </fieldset> @s_ha_dum, what should I do about enctype? can you explain more or link to relative pages? –  Truth May 29 '13 at 7:53
    
edit your question with the additional information. Code is nearly unreadable in the comments. Enctype: stackoverflow.com/questions/4526273/… –  s_ha_dum May 29 '13 at 12:29
    
a file input is for uploading files from a user's local machine, not a web server. see this question about integrating the media window with a plugin. –  Milo May 30 '13 at 15:33
show 5 more comments

1 Answer 1

add_action('post_edit_form_tag', 'post_edit_form_tag');
function post_edit_form_tag() {
    echo ' enctype="multipart/form-data"';
}

Add the above code in your active theme's functions.php file.

Then print_r($_file) will display the file array.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.