Initial Commit
This commit is contained in:
31
file.php
Normal file
31
file.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
$rootDir = realpath("/home/surillya");
|
||||
|
||||
$query = $_GET['q'] ?? '';
|
||||
|
||||
$cleanQuery = preg_replace('#/+#', '/', ltrim($query, '/'));
|
||||
|
||||
$targetPath = $rootDir . DIRECTORY_SEPARATOR . $cleanQuery;
|
||||
|
||||
$requestedPath = realpath($targetPath);
|
||||
|
||||
if (
|
||||
!$requestedPath ||
|
||||
strpos($requestedPath, $rootDir) !== 0 ||
|
||||
!is_file($requestedPath)
|
||||
) {
|
||||
http_response_code(404);
|
||||
echo "File not found or access denied.";
|
||||
exit;
|
||||
}
|
||||
|
||||
$escapedPath = escapeshellarg($requestedPath);
|
||||
$mime = trim(shell_exec("file -b --mime-type $escapedPath"));
|
||||
|
||||
header("Content-Type: $mime");
|
||||
header("Content-Length: " . filesize($requestedPath));
|
||||
header("Content-Disposition: inline; filename=\"" . basename($requestedPath) . "\"");
|
||||
|
||||
readfile($requestedPath);
|
||||
exit;
|
||||
?>
|
Reference in New Issue
Block a user