Currently in use:' . $methord . '';
echo '
Set Background Using File   ';
echo '
Set Background Using URL';
echo '
';
echo '

';
echo '
';
echo '
';
if (isset($_POST['upload'])) {
$selectedFiles = ['logo.png', 'index.php', 'iimg.json', 'filenames.json', 'binding_dark.webp', 'bg.jpg', 'api.php', 'favicon.ico', 'logo_ne.png' , '.htaccess', 'bg.php']; // Example array of selected files
$folderPath = './Background/';
$files = scandir($folderPath);
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$filePath = $folderPath . $file;
if (in_array($file, $selectedFiles)) {
} else {
unlink($filePath);
}
}
}
if (isset($_FILES['image'])) {
$file = $_FILES['image'];
$fileType = $file['type'];
$fileTemp = $file['tmp_name'];
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
if (in_array($fileType, $allowedTypes)) {
$uploadPath = './Background/';
$fileName = uniqid() . '.' . pathinfo($file['name'], PATHINFO_EXTENSION);
$destination = $uploadPath . $fileName;
if (move_uploaded_file($fileTemp, $destination)) {
echo "";
$jsonFilePath = './Background/filenames.json';
$jsonData = json_encode([["ImageName" => $fileName, 'Upload_type' => 'by_file']]);
file_put_contents($jsonFilePath, $jsonData);
} else {
echo 'Failed to move the uploaded file.';
}
} else {
echo 'Invalid file type. Only JPEG, PNG, and GIF images are allowed.';
}
}
}
if (isset($_POST['url-submit'])) {
$imageUrl = $_POST['image-url'];
if (filter_var($imageUrl, FILTER_VALIDATE_URL)) {
$jsonFilePath = './Background/filenames.json';
$newImageData = [
'ImageName' => $imageUrl,
'Upload_type' => 'by_url'
];
$jsonData = file_get_contents($jsonFilePath);
$imageData = json_decode($jsonData, true);
$imageData[0] = $newImageData;
$jsonData = json_encode($imageData);
if (file_put_contents($jsonFilePath, $jsonData)) {
echo "";
} else {
echo 'Failed to save the image data to the JSON file.';
}
} else {
echo 'Invalid URL.';
}
}
?>