Rob Myrick
Rob Myrick

Reputation: 859

Problems copying file to home directory PHP

I'm trying copy a single file from the Plugin directory inside of my Wordpress installation to the root directory of the Wordpress installation. I need the functionality to do this no matter where the installation is located. It's for my Wordpress plugin, and it doesn't seem to be working on a site I tested.

Somehow I'm thinking that I'm not capturing each possible directory location in my function destpath() function. I need it to successfully find the exact directories of the Plugin folder so that it copies the file (process.php) to the exact root directory, no matter the location of the Wordpress install.

function destpath() 
{ 
    $base = dirname(__FILE__); 
    $path = false; 

    if (@file_exists(dirname(dirname($base))."/wp-config.php")) { 
        $path = dirname(dirname($base))."/process.php"; 
    } else 
        if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php")) { 
            $path = dirname(dirname(dirname($base)))."/process.php"; 
        } else 
            $path = false; 

    if ($path != false) { 
        $path = str_replace("\\", "/", $path); 
    } 
    return $path; 
} 

function pluginpath() 
{ 
    $base = dirname(__FILE__); 
    $path = false; 

    if (@file_exists(dirname(dirname($base))."/wp-content/plugins/malware finder/process.php")) { 
        $path = dirname(dirname($base))."/wp-content/plugins/malware finder/process.php"; 
    } else 
        if (@file_exists(dirname(dirname(dirname($base)))."/wp-content/plugins/malware finder/process.php")) { 
            $path = dirname(dirname(dirname($base)))."/wp-content/plugins/malware finder/process.php"; 
        } else 
            $path = false; 

    if ($path != false) { 
        $path = str_replace("\\", "/", $path); 
    } 
    return $path; 
} 

copy(pluginpath(), destpath()); 

Upvotes: 0

Views: 228

Answers (1)

Mike Purcell
Mike Purcell

Reputation: 19999

According to the source code, it looks like the destpath and pluginpath methods of the MalwareFinder class are being injected into the printAdminPage function:

Source code line:83:

function printAdminPage() {

Source code line:108 (appears to close if):

<?php } 

Source code line:111-133 (still within printAdminPage):

function destpath() { ... }

Source code line:136-158 (still within printAdminPage):

function pluginpath() { ... }

Source code line:205:

}//End function printAdminPage()

Also, on lines 62 and 65, these php tags appear unnecessary.

Upvotes: 1

Related Questions