From 8245832be8470f20091eb71946fdeff3cab79aa7 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 4 Jun 2025 18:44:10 +0400 Subject: feat: file page --- public/index.php | 732 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 448 insertions(+), 284 deletions(-) (limited to 'public/index.php') diff --git a/public/index.php b/public/index.php index 053b348..09ab602 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,7 @@ 0) { + $file_id = explode('/', $_SERVER['PHP_SELF']); + $file_id = $file_id[count($file_id) - 1]; + $file_id = explode('.', $file_id); + $file_ext = $file_id[1]; + $file_id = $file_id[0]; + + if (!preg_match('/^[a-zA-Z0-9_-]+$/', $file_id) || !preg_match('/^[a-zA-Z0-9]+$/', $file_ext)) { + http_response_code(404); + exit(); + } + + $file_path = FILE_UPLOAD_DIRECTORY . "/{$file_id}.{$file_ext}"; + $meta_path = FILE_METADATA_DIRECTORY . "/{$file_id}.metadata.json"; + + if (!is_file($file_path)) { + http_response_code(404); + exit(); + } + + if (is_file($meta_path)) { + $file = json_decode(file_get_contents($meta_path), true); + + if (isset($file['views'])) { + session_start(); + + $viewed_file_ids = $_SESSION['viewed_file_ids'] ?? []; + + if (!in_array($file['id'], $viewed_file_ids)) { + $file['views']++; + array_push($viewed_file_ids, $file['id']); + file_put_contents($meta_path, json_encode($file, JSON_UNESCAPED_SLASHES)); + } + + $_SESSION['viewed_file_ids'] = $viewed_file_ids; + + session_commit(); + } + } else { + $file = [ + 'id' => $file_id, + 'extension' => $file_ext, + 'mime' => FILE_ACCEPTED_MIME_TYPES[$file_ext], + 'size' => filesize($file_path) + ]; + } + + $file['full_url'] = FILE_UPLOAD_DIRECTORY_PREFIX . "/{$file['id']}.{$file['extension']}"; + + $size = $file['size']; + $size_suffix = 'B'; + $size_i = 0; + do { + $size /= 1024; + $size_suffix = match ($size_i) { + 0 => 'B', + 1 => 'KB', + 2 => 'MB', + 3 => 'GB', + default => 'TB' + }; + $size_i++; + } while ($size > 1024); + + $file['size_formatted'] = sprintf('%.2f%s', $size, $size_suffix); + $file['name'] = $file['original_name'] ?? sprintf('%s.%s', $file['id'], $file['extension']); + + if (!isset($file['uploaded_at'])) { + $file['uploaded_at'] = filemtime($file_path); + } + + if (str_starts_with($file['mime'], 'image/')) { + $file['resolution'] = trim(shell_exec('identify -format "%wx%h" ' . escapeshellarg($file_path) . '[0]')); + } else if (str_starts_with($file['mime'], 'video/')) { + $info = shell_exec('ffprobe -v error -select_streams v:0 -show_entries stream=width,height,duration -of csv=p=0 ' . escapeshellarg($file_path)); + [$width, $height, $duration] = explode(',', trim($info)); + $file['resolution'] = sprintf('%sx%s (%s seconds)', $width, $height, round($duration, 2)); + } else if (str_starts_with($file['mime'], 'audio/')) { + $file['resolution'] = round(trim(shell_exec('ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ' . escapeshellarg($file_path))), 2) . ' seconds'; + } else if (str_starts_with($file['mime'], 'text/')) { + $file['resolution'] = trim(shell_exec('wc -l < ' . escapeshellarg($file_path))) . ' lines'; + } +} ?> - <?= INSTANCE_NAME ?> + + <?= $file['name'] ?> - <?= INSTANCE_NAME ?> + + <?= INSTANCE_NAME ?> +
- - - -
-
-

What is ?

-
-
-

- is a simple, free and anonymous file sharing site. - We do not store anything other than the files you upload. - They are stored publicly until the heat death of the universe occurs or you hit the DELETE - button. - Users do not need an account to start uploading. -

- Click the button below and share the files with your friends today! -
- But, read TOS and Privacy Policy - before - interacting with the - website. -

-
-
- -
-
-
- -
-
- + +
+ +
+
+

+

()

+ +

+ +
+
+

Uploaded ago

+
+
+ +

views

+ +
-
-
- - -
- - -
-

URL:

-
- - -
-
+ +
+
+
+ +

+ +

File

-
- - +
+ + Image file. + + + + + +
+ +

This file cannot be displayed.

+ +
+
+ + + - - -
-
+
+
+

What is ?

+
+
+

+ is a simple, free and anonymous file sharing site. + We do not store anything other than the files you upload. + They are stored publicly until the heat death of the universe occurs or you hit the DELETE + button. + Users do not need an account to start uploading. +

+ Click the button below and share the files with your friends today! +
+ But, read TOS and Privacy Policy + before + interacting with the + website. +

+
+
- +
+
+
+ +
+
+ +
+
+
+
+ + +
+ + +
+

URL:

+
+ + +
+
+ + +
+ +
+ +
+ + +
+
+
- + + + +
- + + + + \ No newline at end of file -- cgit v1.2.3