prepare("SELECT id, extension FROM files $where_word $in_condition $mime_filter ORDER BY $order_condition LIMIT 1");
if (empty($random_viewed_files)) {
$stmt->execute();
} else {
$stmt->execute($random_viewed_files);
}
if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$file_id = $row['id'];
$file_path = "{$row['id']}.{$row['extension']}";
} else {
$random_viewed_files = array_diff($random_viewed_files, $random_viewed_files);
$in_condition = '';
}
} while (!$file_id || in_array($file_id, $random_viewed_files));
array_push($random_viewed_files, $file_id);
$_SESSION['random_viewed_files'] = $random_viewed_files;
header("Location: /$file_path");
exit;
}
$file = null;
$file_id = null;
$url = parse_url($_SERVER['REQUEST_URI']);
if (strlen($url['path']) > 1) {
$file_id = basename($url['path']);
}
if (FILE_CATALOG_FANCY_VIEW && $file_id) {
$file_id = explode('.', $file_id);
if (count($file_id) != 2) {
http_response_code(404);
exit();
}
$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();
}
$stmt = $db->prepare('SELECT fm.*, f.*,
hb.reason AS ban_reason,
CASE WHEN fb.hash_ban IS NOT NULL THEN 1 ELSE 0 END AS is_banned
FROM files f
LEFT JOIN file_metadata fm ON fm.id = f.id
LEFT JOIN file_bans fb ON fb.id = f.id
LEFT JOIN hash_bans hb ON hb.sha256 = fb.hash_ban
WHERE f.id = ? AND f.extension = ?
');
$stmt->execute([$file_id, $file_ext]);
$file = $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
if (!$file) {
http_response_code(404);
exit();
}
// counting views
$viewed_file_ids = $_SESSION['viewed_file_ids'] ?? [];
if (!in_array($file['id'], $viewed_file_ids)) {
$file['views']++;
array_push($viewed_file_ids, $file['id']);
$db->prepare('UPDATE files SET views = ? WHERE id = ? AND extension = ?')->execute([$file['views'], $file['id'], $file['extension']]);
}
$_SESSION['viewed_file_ids'] = $viewed_file_ids;
if (
isset($file['expires_at']) &&
(
($file['expires_at'] == $file['uploaded_at'] && $file['views'] > 1) ||
($file['expires_at'] != $file['uploaded_at'] && time() > strtotime($file['expires_at']))
)
) {
delete_file($file_id, $file_ext, $db);
http_response_code(404);
exit;
}
if (!FILE_SHOW_UPLOADTIME && !isset($_SESSION['is_moderator'])) {
unset($file['uploaded_at']);
}
if (!FILE_SHOW_VIEWS && !isset($_SESSION['is_moderator'])) {
unset($file['views']);
}
if (IS_JSON_REQUEST) {
unset($file['password']);
$file['urls'] = [
'download_url' => INSTANCE_ORIGINAL_URL . "/{$file['id']}.{$file['extension']}"
];
json_response($file, null);
exit;
}
$file['full_url'] = FILE_UPLOAD_DIRECTORY_PREFIX . "/{$file['id']}.{$file['extension']}";
// formatting the file size
$size = $file['size'];
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
$factor = floor((strlen($size) - 1) / 3);
$file['size_formatted'] = sprintf("%.2f", $size / pow(1024, $factor)) . ' ' . $units[$factor];
$file['name'] = $file['title'] ?? sprintf('%s.%s', $file['id'], $file['extension']);
$file['download_name'] = $file['name'];
if (!str_ends_with($file['download_name'], ".{$file['extension']}")) {
$file['download_name'] .= ".{$file['extension']}";
}
$file['resolution'] = [];
if (isset($file['width'], $file['height'])) {
array_push($file['resolution'], sprintf('%sx%s', $file['width'], $file['height']));
}
if (isset($file['duration'])) {
$dur = format_timestamp(new DateTime()->setTimestamp(time() + $file['duration']));
array_push($file['resolution'], empty($file['resolution']) ? $dur : "($dur)");
}
if (isset($file['line_count'])) {
array_push($file['resolution'], sprintf('%d lines', $file['line_count']));
}
$file['resolution'] = implode(' ', $file['resolution']) ?: null;
$file['html_description'] = $file['mime'] . ' - ' . $file['extension'];
if (isset($file['views'])) {
$file['html_description'] .= " - {$file['views']} views";
}
if (isset($file['uploaded_at'])) {
$file['html_description'] .= ' - Uploaded ' . format_timestamp($file['uploaded_at']) . ' ago';
}
if (isset($file['resolution'])) {
$file['html_description'] .= " - {$file['resolution']}";
}
}
$tos_exists = is_file($_SERVER['DOCUMENT_ROOT'] . '/static/TOS.txt');
$privacy_exists = is_file($_SERVER['DOCUMENT_ROOT'] . '/static/PRIVACY.txt');
?>
= $file['name'] ?> - = INSTANCE_NAME ?>
" />
= INSTANCE_NAME ?>
>
No-JavaScript chad
no fancy features like local file saving
Sorry, you cannot access this file as it violated the TOS and was banned from the
= INSTANCE_NAME ?> servers.
Reason: = $file['ban_reason'] ?>
>
= $file['id'] ?>
= $file['mime'] ?>
= $file['extension'] ?>
= $file['size'] ?>
= $file['title'] ?>
File = sprintf('%s.%s', $file['id'], $file['extension']) ?>
= file_get_contents(FILE_UPLOAD_DIRECTORY . "/{$file['id']}.{$file['extension']}") ?>
JavaScript is required to play Flash
This file cannot be displayed.
= $file['size_formatted'] ?>
= $file['mime'] ?> (= $file['extension'] ?>)
= $file['resolution'] ?>
Uploaded = format_timestamp($file['uploaded_at']) ?> ago
= $file['views'] ?> views
What is = INSTANCE_NAME ?>?
= INSTANCE_NAME ?> 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.