ama girş yapıyorum arama formunda ara diyince çıkış yapıyor
anlayan arkadaşlar bir el atabilirse sevinirim
<style>
/* Ana kutu */
.container {
display: flex;
justify-content: center; /* Ortaya hizalama */
}
/* Arama formu */
.search-form {
display: flex;
align-items: center; /* Dikey hizalama */
justify-content: center; /* Yatay hizalama */
margin: 0 20px; /* Sağ ve sol boşluk */
}
.search-form input[type="text"] {
width: 300px;
padding: 10px;
font-size: 16px;
border: none;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.search-form button[type="submit"] {
padding: 8px 12px;
border-radius: 4px;
border: none;
background-color: #007bff;
color: #fff;
font-size: 16px;
margin-left: 10px; /* Boşluk */
}
/* Çıkış formu */
.logout-form {
margin-right: 20px; /* Sağ boşluk */
margin-top: 20px; /* Üst boşluk */
}
.logout-form input[type="submit"] {
padding: 8px 12px;
border-radius: 4px;
border: none;
background-color: #008CBA;
color: #fff;
font-size: 16px;
}
/* body style */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
}
/* table style */
table {
width: 100%;
border-collapse: collapse;
margin: 20px auto;
background-color: white;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 5px;
text-align: left;
border: 1px solid #ddd;
}
th {
background-color: #008CBA;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
/* button group style */
div button {
margin-right: 10px;
padding: 10px 20px;
font-size: 16px;
border: none;
border-radius: 5px;
background-color: #008CBA;
color: white;
cursor: pointer;
}
/* link style */
a {
color: #008CBA;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.button-group {
display: flex;
justify-content: flex-start;
align-items: center;
margin-top: 10px;
}
.button-group button {
margin-right: 10px;
}
.checkbox {
display: inline-block;
vertical-align: middle;
margin-right: 5px;
}
.checkbox-label {
display: inline-block;
vertical-align: middle;
color: #333;
}
.alert {
padding: 8px;
background-color: #f44336;
color: black;
margin-bottom: 15px;
background-image: url('https://cdn1.iconfinder.com/data/icons/ionicons-outline-vol-2/512/warning-outline-20.png');
background-repeat: no-repeat;
background-position: 10px center;
background-size: 20px 20px;
padding-left: 40px;
border: 1px solid black;
}
.alert p {
margin: 0;
font-size: 15px;
font-weight: bold;
}
</style>
<?php
session_start(); // oturumu başlat
// oturum sonlandırma işlemi
if(isset($_POST['logout'])) {
session_destroy(); // oturumu sonlandır
header('Location: ' . $_SERVER['PHP_SELF']); // sayfayı yenile
}
// üye giriş işlemi
if(isset($_POST['login'])) {
$username = 'kullanici';
$password = 'sifre';
if($_POST['username'] == $username && $_POST['password'] == $password) {
$_SESSION['logged_in'] = true; // oturum değişkeni oluştur
header('Location: ' . $_SERVER['PHP_SELF']); // sayfayı yenile
} else {
echo '<div class="alert">';
echo '<p>Kullanıcı adı veya şifre hatalı.</p>';
echo '</div>';
}
}
// eğer oturum değişkeni varsa kullanıcı giriş yapmıştır
if(isset($_SESSION['logged_in'])) {
echo '<p>Hoş geldiniz, kullanıcı!</p>';
echo ' <div class="logout-form">';
echo '<form method="POST" >';
echo '<button type="submit" name="logout">Çıkış Yap</button>';
echo '</form>';
echo '</div>';
echo '<form method="POST" class="search-form">';
echo ' <input type="text" name="search" id="search" placeholder="Dosya Ara">';
echo ' <button type="submit" name="ara">Ara</button>';
echo '</form>';
} else {
echo '<form method="POST" class="giris-form">';
echo '<input type="text" name="username" placeholder="Kullanıcı Adı">';
echo '<input type="password" name="password" placeholder="Şifre">';
echo '<button type="submit" name="login">Giriş Yap</button>';
echo '</form>';
}
?>
<?php
if(isset($_POST['search'])) {
$search_term = $_POST['search'];
$dir = '.';
$files = search_files($dir, $search_term);
$num_results = count($files);
echo '<div class="alert">';
echo "<p>$num_results sonuç bulundu.</p>";
echo '</div>';
if($num_results > 0) {
echo "<form method='POST'>";
echo '<div class="button-group">';
echo "<button type='button' onclick='selectAll()'>Tümünü Seç</button>";
echo "<button type='button' onclick='unselectAll()'>Seçimi Kaldır</button>";
echo "<button type='submit' name='delete_selected'>Sil</button>";
echo '<button onclick="window.history.back()">Geri Dön</button>';
echo "</div>";
echo "<table>";
echo "<thead><tr><th>Sil</th><th>Dosya Adı</th><th>Boyut</th></tr></thead><tbody>";
foreach($files as $file) {
$file_type = is_dir($file) ? 'Klasör' : 'Dosya';
$file_size = filesize($file);
$file_size_formatted = format_file_size($file_size);
echo "<tr><td><input type='checkbox' name='delete[]' value='$file'></td><td><a href='$file' target='_blank'>$file</a></td><td>$file_size_formatted</td>
</tr>";
}
echo "</tbody></table>";
echo '<div class="button-group">';
echo "<button type='button' onclick='selectAll()'>Tümünü Seç</button>";
echo "<button type='button' onclick='unselectAll()'>Seçimi Kaldır</button>";
echo "<button type='submit' name='delete_selected'>Sil</button>";
echo '<button onclick="window.history.back()">Geri Dön</button>';
echo "</div>";
echo "</form>";
}
}
function format_file_size($bytes) {
$sizes = array('Bytes', 'KB', 'MB', 'GB', 'TB');
if ($bytes == 0) return 'n/a';
$i = floor(log($bytes) / log(1024));
return round($bytes / pow(1024, $i), 2) . ' ' . $sizes[$i];
}
if(isset($_POST['delete_selected'])) {
$files_to_delete = $_POST['delete'];
$num_deleted_files = 0;
$total_deleted_size = 0;
if(!empty($files_to_delete)) {
foreach($files_to_delete as $file) {
if(is_file($file)) {
$file_size = filesize($file);
if(unlink($file)) {
$num_deleted_files++;
$total_deleted_size += $file_size;
}
} else {
list($deleted_files, $deleted_size) = delete_directory($file);
$num_deleted_files += $deleted_files;
$total_deleted_size += $deleted_size;
}
}
echo '<div class="alert">';
echo "<p>$num_deleted_files dosya başarıyla silindi. Toplam silinen boyut: " . format_size($total_deleted_size) . "</p>";
echo '</div>';
echo '<button onclick="window.history.back()">Geri Dön</button>';
}
}
function search_files($dir, $search_term) {
$results = array();
$files = scandir($dir);
foreach($files as $file) {
if($file == '.' || $file == '..') continue;
$path = $dir . '/' . $file;
if(is_dir($path)) {
$results = array_merge($results, search_files($path, $search_term));
} else {
if(strpos($file, $search_term) !== false) {
$results[] = $path;
}
}
}
return $results;
}
function delete_directory($dir) {
$num_deleted_files = 0;
$total_deleted_size = 0;
if(is_dir($dir)) {
$objects = scandir($dir);
foreach($objects as $object) {
if($object != '.' && $object != '..') {
$path = $dir . '/' . $object;
if(is_dir($path)) {
list($deleted_files, $deleted_size) = delete_directory($path);
$num_deleted_files += $deleted_files;
$total_deleted_size += $deleted_size;
} else {
$file_size = filesize($path);
if(unlink($path)) {
$num_deleted_files++;
$total_deleted_size += $file_size;
}
}
}
}
if(rmdir($dir)) {
$num_deleted_files++;
}
}
return array($num_deleted_files, $total_deleted_size);
}
function format_size($size) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$i = 0;
while($size > 1024) {
$size /= 1024;
$i++;
}
return round($size, 2) . ' ' . $units[$i];
}
?>
<script>
function selectAll() {
var checkboxes = document.getElementsByName('delete[]');
for(var i=0; i<checkboxes.length; i++) {
checkboxes[i].checked = true;
}
}
function unselectAll() {
var checkboxes = document.getElementsByName('delete[]');
for(var i=0; i<checkboxes.length; i++) {
checkboxes[i].checked = false;
}
}
</script>
