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 +++++++++++++++++++++++--------------- public/static/img/brand/mini.webp | Bin 0 -> 1922 bytes public/static/style.css | 15 + public/upload.php | 2 + 4 files changed, 465 insertions(+), 284 deletions(-) create mode 100644 public/static/img/brand/mini.webp (limited to 'public') 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 diff --git a/public/static/img/brand/mini.webp b/public/static/img/brand/mini.webp new file mode 100644 index 0000000..2f6de74 Binary files /dev/null and b/public/static/img/brand/mini.webp differ diff --git a/public/static/style.css b/public/static/style.css index e0ae3e0..f22bac2 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -136,6 +136,13 @@ button[type=submit]:hover { background: var(--box-content-background-2); } +/** FILES */ +.file-preview img, +.file-preview video { + width: 100%; + max-height: 100%; +} + /** SHORTCUTS */ .column { display: flex; @@ -163,10 +170,18 @@ button[type=submit]:hover { justify-content: center; } +.justify-end { + justify-content: end; +} + .align-center { align-items: center; } +.align-bottom { + align-items: end; +} + .pad-4 { padding: 4px; } diff --git a/public/upload.php b/public/upload.php index 1f5b838..0d8a7e3 100644 --- a/public/upload.php +++ b/public/upload.php @@ -176,6 +176,8 @@ try { if (FILE_METADATA) { unset($file_data['urls']); $file_data['password'] = password_hash($file_data['password'], PASSWORD_DEFAULT); + $file_data['views'] = 0; + $file_data['uploaded_at'] = time(); if (!is_dir(FILE_METADATA_DIRECTORY) && !mkdir(FILE_METADATA_DIRECTORY, 0777, true)) { throw new RuntimeException('Failed to create a folder for file metadata'); } -- cgit v1.2.3