Support » Plugins and Hacks » Hacks » Creating a folder & moving a file.

  • I have a plugin that has a file located in wp-content/plugins/my_plugin/inc/file.php How can I create a new directory outside of wp-content and copy that file to the new folder when the plugin is activated?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Just place the file where you want it and update the line that includes that file to point to the new location. Upload the file you edit the file location in so that it is loading the file from the new location before deleting the old file.php.

    Moderator bcworkz


    Or do you mean how is it done with php when your plugin is activated on anyone’s server?

    Use the functions mkdir() and copy()

    Thank you. I was able to work something out, my code for anyone interested

    function docu_docsetup() {
    	define("PLUGIN_PATH", plugin_dir_path(__FILE__));
    	$copy_from = PLUGIN_PATH . "inc";
    	$copy_to = ABSPATH . "doc";
    	if(!is_dir(ABSPATH . '/doc')) {
              mkdir(ABSPATH . '/doc',0755);
    	if(!file_exists(ABSPATH . '/doc/dl.php')) {
              copy($copy_from . "/dl.php", $copy_to . "/dl.php");
    register_activation_hook( __FILE__, 'docu_docsetup' );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating a folder & moving a file.’ is closed to new replies.