WordPress.org

Ready to get started?Download WordPress

Forums

Creating a folder & moving a file. (4 posts)

  1. UncleCali
    Member
    Posted 1 year ago #

    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?

  2. alieneila
    Member
    Posted 1 year ago #

    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.

  3. bcworkz
    Member
    Posted 1 year ago #

    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()

  4. UncleCali
    Member
    Posted 1 year ago #

    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' );

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.