Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[WordPress] Uploading Files to a Custom Directory in WordPress
// 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 );
// 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 )

This comment has been minimized.

Copy link

@vairafiq vairafiq commented Mar 19, 2018

 $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