Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created September 2, 2016 12:39
Show Gist options
  • Save tommcfarlin/c634133cb0a49305f554376e8da6c06a to your computer and use it in GitHub Desktop.
Save tommcfarlin/c634133cb0a49305f554376e8da6c06a to your computer and use it in GitHub Desktop.
[WordPress] Uploading Files to a Custom Directory in WordPress
<?php
// First, make sure the directory to which we want to upload exists.
$uploads_dir = trailingslashit( plugin_dir_path( dirname( __FILE__ ) ) ) . 'uploads';
wp_mkdir_p( $uploads_dir );
<?php
// Now we'll move the temporary file to this plugin's uploads directory.
$source = $_FILES['acme-imported-file']['tmp_name'];
$destination = trailingslashit( $uploads_dir ) . $_FILES['acme-imported-file']['name'];
move_uploaded_file( $source, $destination )
@vairafiq
Copy link

 $txtPhoto      = isset($_FILES['txtPhoto']) ? $_FILES['txtPhoto'] : '';

                

              //moving image to the plugin directory
                $source      = $txtPhoto;

                $uploads_dir = trailingslashit( plugin_dir_path( dirname( __FILE__ ) ) ) . 'images';
                wp_mkdir_p( $uploads_dir );

                $destination = trailingslashit( $uploads_dir ) . $txtPhoto;

                move_uploaded_file( $source, $destination );

here is my code as you show, but unfortunately it doesn't work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment