<?php
$erorr = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $folderName = $_POST['folderName'];
    
    $folderName = preg_replace('/[^a-zA-Z0-9_\-]/', '', $folderName);
    
    $path = dirname(__DIR__) . DIRECTORY_SEPARATOR . $folderName;

    if (!is_dir($path)) {
        if (mkdir($path, 0777, true)) {
            echo " Folder in path:" . $path . " was made";
        } else {
            $erorr = "Error creating folder!";
        }
    } else {
        $erorr = " The folder already exists.";
    }
}
?>
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <!-- Always force latest IE rendering engine or request Chrome Frame -->
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <!-- Use title if it's in the page YAML frontmatter -->
    <title>Welcome to host downlod</title>

    <meta name="description" content="XAMPP is an easy to install Apache distribution containing MariaDB, PHP and Perl." />
    <meta name="keywords" content="xampp, apache, php, perl, mariadb, open source distribution" />

    <link href="stylesheets/normalize.css" rel="stylesheet" type="text/css" /><link href="/dashboard/stylesheets/all.css" rel="stylesheet" type="text/css" />
    <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

    <script src="javascripts/modernizr.js" type="text/javascript"></script>


    <link href="logo.png" rel="icon" type="image/png" />

<style>
    body {
        font-family: Arial, sans-serif;
    }
    .file-list {
        margin: 10px;
        padding: 0;
        list-style: none;
    }
    .file-list li {
        padding: 5px;
        border-bottom: 1px solid #ccc;
    }
    .file-list li a {
        text-decoration: none;
        color: #333;
    }
    .file-list li a:hover {
        text-decoration: underline;
        color: #007BFF;
    }
  
</style>
  </head>

  <body class="index">
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=277385395761685";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    <header class="header contain-to-grid">
      <nav class="top-bar" data-topbar>

        <section class="top-bar-section">
          <!-- Left Nav Section -->
          <ul class="left">
              <li class="item "><a target="_blank" href="https://greatonedeveloper.ir/">great one developer</a></li>
              <li class="item "><a target="_blank" href="https://anime.greatonedeveloper.ir/">&#1614;Anime</a></li>
          </ul>
        </section>
      </nav>
    </header>

    <div class="wrapper">
      <div class="hero">
<h1 style="text-align:center">Files list</h1>
<? echo $erorr ?>
<hr>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
  <label for="add" style="margin-left: 2%;">
    &#128450; add folder
  </label>
  <div style="display: flex; align-items: baseline;">

    <input type="text" name="folderName" id="add" placeholder="folder name" style="width: 50%;margin-left: 2%; height: 3rem;">
    <input type="submit" value="+" style="background-color: #2a5d84;
    margin-left: 1rem;
    width: 5vw;
    height: 4vw;
    border: solid 0px;
    border-radius: 25px;">
  </form>
</div>

<ul class="file-list">
    <?php
    $directory = "/"; // Replace with the path to your directory
    $files = scandir($directory); // Replace with the path to your directory
    foreach ($files as $file) {
        if ($file !== "." && $file !== ".." && $file !== "index.php") { // Replace with the path to your directory
        ?>
            <li><a href='/<?php $file ?>'><?php $file ;?></a></li>
            <?php
        }
    }
    ?>
</ul>


    </div>

    <footer class="footer row">
      <div class="columns">
        <div class="footer_lists-container row collapse">
          <div class="footer_social columns large-2">
            <ul class="social">
  <li class="twitter"><a href="https://x.com/jowzefy">Follow us on Twitter</a></li>
  <li class="facebook"><a href="https://www.linkedin.com/in/jowzefy">Like us on Linkdin</a></li>
  <li class="facebook"><a href="https://www.github.com/jowzefy">Like us on Github</a></li>
</ul>

            <p class="footer_copyright">Copyright (c) 2022, Apache Friends</p>
          </div>

        </div>
      </div>
    </footer>

    <!-- JS Libraries -->
    <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="/dashboard/javascripts/all.js" type="text/javascript"></script>
  </body>
</html>
