Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy move_uploaded_file method does not work in WordPress?
    primarykey
    data
    text
    <p>I created a metabox in wordpress for uploading photo to my plugin custom directory. I used the following code</p> <pre><code>&lt;form method="post" enctype="multipart/form-data"&gt; &lt;input type="file" name="taggr_upload"&gt; &lt;/form&gt; </code></pre> <p>This is the form I created in side the <code>add_meta_box()</code> method</p> <p>Then I add this save_post action hook</p> <pre><code>add_action( 'save_post', 'boj_mbe_save_meta' ); function boj_mbe_save_meta( $post_id ) { move_uploaded_file($_FILES['taggr_upload']['tmp_name'], 'photo/'. basename( $_FILES['taggr_upload']['name'] )); } </code></pre> <p>Why it doesn't save into my photo folder when I open my folder?</p> <p>This is the full code:</p> <pre><code>&lt;?php /* Plugin Name: random plug Plugin URI: http://example.com/wordpress-plugins/my-plugin Description: A plugin demonstrating Cron in WordPress Version: 1.0 Author: Brad Williams Author URI: http://wrox.com License: GPLv2 */ add_action('init', 'register_tagging_post'); function register_tagging_post(){ $tagging_args = array( 'public' =&gt; true, 'supports' =&gt; array( 'title', 'thumbnail' ), 'query_var' =&gt; 'tagging', 'rewrite' =&gt; array( 'slug' =&gt; 'tagging', 'with_front' =&gt; false ), 'labels' =&gt; array( 'name' =&gt; 'Albums', 'singular_name' =&gt; 'Album', 'add_new' =&gt; 'Add New Album', 'add_new_item' =&gt; 'Add New Album', 'edit_item' =&gt; 'Edit Album', 'new_item' =&gt; 'New Album', 'view_item' =&gt; 'View Album', 'search_items' =&gt; 'Search Albums', 'not_found' =&gt; 'No Albums Found', 'not_found_in_trash' =&gt; 'No Albums Found In Trash' ), ); register_post_type('tagging', $tagging_args); } //add metabox add_action( 'add_meta_boxes', 'boj_mbe_create' ); function boj_mbe_create() { //create a custom meta box add_meta_box( 'boj-meta', 'My Custom Meta Box', 'boj_mbe_function', 'tagging', 'normal', 'high' ); } function boj_mbe_function( $post ) { //retrieve the meta data values if they exist ?&gt; &lt;form method="post" enctype="multipart/form-data"&gt; &lt;input type="file" name="taggr_upload"&gt; &lt;/form&gt; &lt;?php echo WP_PLUGIN_DIR; //hook to save the meta box data add_action( 'save_post', 'boj_mbe_save_meta' ); function boj_mbe_save_meta( $post_id ) { //verify the meta data is set if ( isset( $_POST['taggr_upload'] ) ) { //save the meta data $path_to_plugin = WP_PLUGIN_DIR . '/yeah'; move_uploaded_file($_FILES['taggr_upload']['tmp_name'], $path_to_plugin . '/photo/'. basename( $_FILES['taggr_upload']['name'] )); } } //create custom post column } ?&gt; </code></pre> <p>Why it doesn't work?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload