diff options
Diffstat (limited to 'resources/views/f_v1.blade.php')
| -rw-r--r-- | resources/views/f_v1.blade.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/resources/views/f_v1.blade.php b/resources/views/f_v1.blade.php new file mode 100644 index 0000000..cff2a4f --- /dev/null +++ b/resources/views/f_v1.blade.php @@ -0,0 +1,79 @@ +@extends('template') +<?php + $baseDir = 'storage/uploads/'; + $currentDir = $baseDir; + + //use this if want to require auth + /*$valid_username = 'admin'; // Set your username + $valid_password = 'password'; // Set your password + if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || + $_SERVER['PHP_AUTH_USER'] != $valid_username || $_SERVER['PHP_AUTH_PW'] != $valid_password) { + header('WWW-Authenticate: Basic realm="Secure Directory"'); + header('HTTP/1.0 401 Unauthorized'); + echo 'Authentication required'; + exit; + }*/ + + // check if requested file or directory + if (isset($_GET['file'])) { + $fileRequested = $_GET['file']; + $filePath = realpath($fileRequested); + + if (file_exists($filePath) && is_file($filePath)) { + // Set headers to force download + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="' . basename($filePath) . '"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: ' . filesize($filePath)); + readfile($filePath); + exit; + } else { + echo "File not found."; + exit; + } + } else if (isset($_GET['dir'])) { + $dir = $_GET['dir']; + if (strpos($dir, '..') !== false || strpos($dir, '/') !== false || strpos($dir, '\\') !== false) { + echo 'Access Denied'; + exit; + } + $dir= basename($dir); // Ensuring the folder name is isolated + if (!is_dir("${baseDir}/${dir}")) { + echo 'Directory not found'; + exit; + } + $currentDir = "${baseDir}/${dir}"; + } + + // Extracting the name of the current directory + $currentDirName = basename($currentDir); + + // Determine the depth of the current directory relative to the base directory + $depth = substr_count(str_replace($baseDir, '', $currentDir), '/'); + + $contents = scandir($currentDir); +?> +@section('body') +<main> + <!--<p><b>Contents of:</b> <em> {{ $currentDir }}</em></p>--> + <p><b>{{ htmlspecialchars(ucfirst($currentDirName)) }}</b></p> + <ul> + @foreach ($contents as $item) + @if ($item !== "." && $item !== "..") + <li> + @if (is_dir($currentDir . '/' . $item)) + <strong>Directory:</strong> <a href="?dir={{ $item }}">{{ htmlspecialchars($item) }}</a> + @else + <a href="/f/{{ $item }}">{{ htmlspecialchars($item) }}</a> + @endif + </li> + @endif + @endforeach + @if ($currentDir != $baseDir) + <li><a href="/f?dir={{ $currentDirName }}">Go Up</a></li> + @endif +</main> +@endsection
\ No newline at end of file |
