I am trying to copy a directory, subdirectories and files to another location with php. I am using the following script:
recurseCopy("../storage", "storage2");
function recurseCopy($src, $dst)
{
$dir = opendir($src);
mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
$this->recurseCopy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
I'm pretty sure the issue has something to do with a static method being called but I don't know enough to be able to fix it. Here is my exact error:
[19-May-2022 10:44:25 America/New_York] PHP Fatal error: Uncaught Error: Using $this when not in object context in /home/fenchxvj/public_html_dev/dir-copy-func/index.php:10
Stack trace:
#0 /home/fenchxvj/public_html_dev/dir-copy-func/index.php(2): recurseCopy('../storage', 'storage2')
#1 {main}
thrown in /home/fenchxvj/public_html_dev/dir-copy-func/index.php on line 10