This commit is contained in:
Flatlogic Bot 2025-10-01 07:01:16 +00:00
parent 830133f4aa
commit 24c0e7b2b3
3 changed files with 107 additions and 1 deletions

41
admin.php Normal file
View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Panel</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h3>Admin Panel</h3>
</div>
<div class="card-body">
<h5 class="card-title">Logo Management</h5>
<p class="card-text">Upload a new logo for the site. The current logo will be replaced. The file should be a PNG, JPG, or GIF.</p>
<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success">Logo uploaded successfully!</div>
<?php elseif (isset($_GET['error'])): ?>
<div class="alert alert-danger">Error uploading logo: <?php echo htmlspecialchars($_GET['error']); ?></div>
<?php endif; ?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<div class="mb-3">
<label for="logoFile" class="form-label">Select image:</label>
<input class="form-control" type="file" name="logoFile" id="logoFile" required>
</div>
<button type="submit" class="btn btn-primary">Upload Logo</button>
</form>
</div>
<div class="card-footer text-center">
<a href="/" class="btn btn-secondary">Back to Home</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -77,10 +77,21 @@ $contacts = [
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top"> <nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="#"> <a class="navbar-brand d-flex align-items-center" href="/">
<?php
$logo_path = glob('assets/images/logo.*');
if ($logo_path) {
echo '<img src="' . $logo_path[0] . '?v=' . time() . '" alt="Logo" style="max-height: 40px; margin-right: 10px;">';
}
?>
<i class="bi bi-book-half me-2"></i> <i class="bi bi-book-half me-2"></i>
rehber rehber
</a> </a>
<div class="ms-auto">
<a href="/admin.php" class="btn btn-outline-secondary btn-sm">
<i class="bi bi-gear-fill me-1"></i> Admin Panel
</a>
</div>
</div> </div>
</nav> </nav>

54
upload.php Normal file
View File

@ -0,0 +1,54 @@
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['logoFile'])) {
$targetDir = "assets/images/";
// Ensure the target directory exists
if (!is_dir($targetDir)) {
mkdir($targetDir, 0775, true);
}
$original_filename = $_FILES["logoFile"]["name"];
$imageFileType = strtolower(pathinfo($original_filename, PATHINFO_EXTENSION));
// Use a consistent name for the logo file to make it easy to reference
$targetFile = $targetDir . "logo." . $imageFileType;
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["logoFile"]["tmp_name"]);
if($check === false) {
header("Location: admin.php?error=File is not an image.");
exit;
}
// Allow certain file formats
$allowed_types = ["jpg", "png", "jpeg", "gif"];
if(!in_array($imageFileType, $allowed_types)) {
header("Location: admin.php?error=Sorry, only JPG, JPEG, PNG & GIF files are allowed.");
exit;
}
// Before uploading, remove any old logo files to avoid conflicts
$existing_logos = glob($targetDir . "logo.*_old");
foreach ($existing_logos as $old_logo) {
unlink($old_logo);
}
// Check if a logo already exists and rename it
$current_logo_path = glob($targetDir . "logo.*_old");
if (!empty($current_logo_path)) {
rename($current_logo_path[0], $targetDir . "logo." . pathinfo($current_logo_path[0], PATHINFO_EXTENSION) . "_old");
}
// Try to upload file
if (move_uploaded_file($_FILES["logoFile"]["tmp_name"], $targetFile)) {
header("Location: admin.php?success=1");
exit;
} else {
header("Location: admin.php?error=Sorry, there was an error uploading your file.");
exit;
}
} else {
// Redirect back to admin page if accessed directly
header("Location: admin.php");
exit;
}
?>