<?php
function convertToReadableSize($size){
  $base = log($size) / log(1024);
  $suffix = array("", "KB", "MB", "GB", "TB");
  $f_base = floor($base);
  return round(pow(1024, $base - floor($base)), 1) . ' ' . $suffix[$f_base];
}
include ('includes/header.php');
?>

<link rel="stylesheet"href="https://use.fontawesome.com/releases/v5.3.1/css/all.css"integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://use.fontawesome.com/releases/v5.0.1/css/all.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<!DOCTYPE html>
<html>
<body>
            <div class="col-md-8 mx-auto">
            <div class="card-body">
                <div class="card bg-primary text-white">
                    <div class="card-header card-header-warning">
                        <center>
                            <h2><i class="fa fa-upload"></i> Upload Files</h2>
                        </center>
                    
                    <!--<a data-toggle="tooltip" title="settings" class="fas fa-cogs fa-lg text-light" href="settings.php" role="button" aria-disabled="true"></a>-->
                    <?php
                        $files = scandir("uploads/");
                    for 
                        ($a = 2; $a < count($files); $a++)
                      {
                    ?>
            <!--<a data-toggle="tooltip" title="Download App" href="uploads/<?php echo $files[$a]; ?>" download="<?php echo $files[$a]; ?>" class="fas fa-download fa-lg text-success"></a>-->
              <?php
            }
        ?>
         
            </div>
            <div class="card-header card-header-warning">
                <center>
                    <p class="font-weight-bold text-white"><i class="fa fa-exclamation-triangle text-warning"></i>Your files will be uploaded to here.. https://<?php echo $_SERVER["HTTP_HOST"]; ?>/uploads</p><p class="font-weight-bold text-white">followed by the files name or simply copy the url from the preview page!</p>
                </center>
            </div>
            <center>
            </center>

            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="application_tab">
                    <div class="card bg-dark text-white">
                        <div class="card-body">
                           <center>                
<form method="POST" action="uploadcom.php" enctype="multipart/form-data">
<div class="input-group mb-3">
  <div class="custom-file">
    <input type="file" class="custom-file-input" name="file">
    <label class="custom-file-label" for="file">Choose file</label>
  </div>
  <div class="input-group-append text-info">

    <button type="submit" value="Upload" class="btn btn-primary">upload</button>
  </div>
</div>
</form>
</center>
<br>
<div class="card-body table-responsive">
<table class="table table-striped table-dark">
<tr>
<th>ID</th>
<th>Name</th>
<th>Size</th>
<th>Action</th>
</tr>
<?php
$files = array_values(array_diff(scandir('uploads/'), ['.', '..']));
if($files){
for ($a=0; $a<count($files); $a++){
    ?>
    <tr>
        <td><?php echo $a+1; ?></td>
        <td><b style="color:#fec60f"><?php echo $files[$a]; ?></b></td>
        <td><?php echo convertToReadableSize(filesize('uploads/'.$files[$a])); ?></td>
        <td>
            <a href="uploads/<?php echo $files[$a]; ?>" <a href"<?php echo $files[$a]; ?>">
            <i data-toggle="tooltip" title="Preview" class="fas fa-eye fa-lg" style="color:#fec60f"></i></a> |
        <a href="uploads/<?php echo $files[$a]; ?>" download="<?php echo $files[$a]; ?>">
            <i data-toggle="tooltip" title="Download Img" class="fas fa-download fa-lg" style="color:#fec60f"></i>
        </a> | <a href="delete.php?name=uploads/<?php echo $files[$a]; ?>">
            <i data-toggle="tooltip" title="Delete Img" class="far fa-trash-alt fa-lg text-danger"></i>
        </a></td>
    </tr>
    <?php
}
}
else echo '<tr><td  colspan="4" style="color:#fec60f;" <p class="text-center"><i class="fas fa-inbox" style="font-size: 40px;"></i><br>No files uploaded!</p></td></tr>';
?>
</table>

<?php include ('includes/footer.php');?>
</script>
</body>
</html>

