Compare commits

...

1 Commits

Author SHA1 Message Date
Flatlogic Bot
d750ec3f29 1766739644493 2025-12-26 09:00:50 +00:00
5 changed files with 429 additions and 141 deletions

18
assets/css/custom.css Normal file
View File

@ -0,0 +1,18 @@
body {
background-color: #F8F9FA;
}
.hero {
background: linear-gradient(135deg, #0D6EFD, #6f42c1);
color: white;
padding: 4rem 0;
text-align: center;
}
.upload-section, .files-section {
background-color: #FFFFFF;
padding: 2rem;
border-radius: 0.5rem;
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
margin-bottom: 2rem;
}

1
assets/js/main.js Normal file
View File

@ -0,0 +1 @@
// Future javascript for progress bars and dynamic uploads

24
db/database.php Normal file
View File

@ -0,0 +1,24 @@
<?php
require_once 'config.php';
try {
$conn = db();
// Create database if it doesn't exist
$conn->exec("CREATE DATABASE IF NOT EXISTS " . getenv('DB_NAME'));
$conn->exec("USE " . getenv('DB_NAME'));
// Create table for files
$sql = "CREATE TABLE IF NOT EXISTS files (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(255) NOT NULL,
filesize INT(11) NOT NULL,
filetype VARCHAR(50) NOT NULL,
upload_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
$conn->exec($sql);
echo "Database and table created successfully.";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>

28
delete.php Normal file
View File

@ -0,0 +1,28 @@
<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['filename'])) {
$filename = basename($_POST['filename']);
$uploadDir = 'uploads/';
$targetFile = $uploadDir . $filename;
if (file_exists($targetFile) && realpath($targetFile) == realpath($uploadDir . $filename)) {
if (unlink($targetFile)) {
try {
$conn = db();
$stmt = $conn->prepare("DELETE FROM files WHERE filename = ?");
$stmt->execute([$filename]);
header("Location: index.php?message=File+deleted+successfully&type=success");
} catch (PDOException $e) {
header("Location: index.php?message=File+deleted+but+database+error:+" . $e->getMessage() . "&type=danger");
}
} else {
header("Location: index.php?message=Error+deleting+file&type=danger");
}
} else {
header("Location: index.php?message=File+not+found+or+invalid&type=danger");
}
} else {
header("Location: index.php");
}
?>

491
index.php
View File

@ -1,150 +1,367 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
require_once 'db/config.php';
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
$message = '';
$message_type = 'danger';
if (isset($_GET['message'])) {
$message = htmlspecialchars($_GET['message']);
if (isset($_GET['type'])) {
$message_type = htmlspecialchars($_GET['type']);
}
}
$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$conn = db();
if (isset($_FILES['fileToUpload'])) {
$targetFile = $uploadDir . basename($_FILES["fileToUpload"]["name"]);
$stmt = $conn->prepare("SELECT 1 FROM files WHERE filename = ?");
$stmt->execute([basename($_FILES["fileToUpload"]["name"])]);
if ($stmt->fetch()) {
$message = "Sorry, file already exists.";
$message_type = 'danger';
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {
$stmt = $conn->prepare("INSERT INTO files (filename, filesize, filetype) VALUES (?, ?, ?)");
$stmt->execute([
basename($_FILES["fileToUpload"]["name"]),
$_FILES["fileToUpload"]["size"],
$_FILES["fileToUpload"]["type"]
]);
$message = "The file ". htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded.";
$message_type = 'success';
} else {
$message = "Sorry, there was an error uploading your file.";
$message_type = 'danger';
}
}
} elseif (isset($_POST['remote_url'])) {
$url = filter_var($_POST['remote_url'], FILTER_VALIDATE_URL);
if ($url) {
$fileName = basename(parse_url($url, PHP_URL_PATH));
if (empty($fileName)) {
$fileName = 'remote_file_' . time();
}
$targetFile = $uploadDir . $fileName;
$stmt = $conn->prepare("SELECT 1 FROM files WHERE filename = ?");
$stmt->execute([$fileName]);
if ($stmt->fetch()) {
$message = "Sorry, a file with the name '{$fileName}' already exists.";
$message_type = 'danger';
} else {
$content = @file_get_contents($url);
if ($content !== false) {
if (file_put_contents($targetFile, $content)) {
$stmt = $conn->prepare("INSERT INTO files (filename, filesize, filetype) VALUES (?, ?, ?)");
$stmt->execute([
$fileName,
strlen($content),
mime_content_type($targetFile) // Guess mime type
]);
$message = "The file from URL has been uploaded as '{$fileName}'.";
$message_type = 'success';
} else {
$message = "Sorry, there was an error saving the remote file.";
$message_type = 'danger';
}
} else {
$message = "Sorry, could not retrieve the file from the specified URL.";
$message_type = 'danger';
}
}
} else {
$message = "Invalid URL provided.";
$message_type = 'danger';
}
}
}
?>
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<?php
// Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?>
<?php if ($projectDescription): ?>
<!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Files Cloud</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
</head>
<body>
<main>
<div class="card">
<h1>Analyzing your requirements and generating your website…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
<header class="hero">
<div class="container">
<h1 class="display-4">My Files Cloud</h1>
<p class="lead">Your personal cloud storage solution.</p>
</div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
</header>
<main class="container my-5">
<?php if ($message): ?>
<div class="alert alert-<?php echo $message_type; ?> alert-dismissible fade show" role="alert">
<?php echo $message; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<section class="upload-section">
<h2><i class="bi bi-cloud-arrow-up"></i> Upload Files</h2>
<p>Storage Capacity: Unlimited</p>
<form action="index.php" method="post" enctype="multipart/form-data" id="uploadForm">
<div class="mb-4">
<label for="file-upload" class="form-label"><strong>Upload from your device</strong></label>
<div class="input-group">
<input type="file" class="form-control" id="file-upload" name="fileToUpload" required>
<button class="btn btn-primary" type="submit" id="uploadButton">Upload</button>
</div>
<div class="progress mt-2" style="height: 5px;">
<div class="progress-bar" role="progressbar" id="uploadProgressBar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<small class="form-text text-muted">Max. file size: 9999 PB</small>
</div>
</form>
<form action="index.php" method="post" id="remoteUploadForm">
<div class="mb-4">
<label for="remote-url-upload" class="form-label"><strong>Upload from a remote URL</strong></label>
<div class="input-group">
<input type="url" class="form-control" id="remote-url-upload" name="remote_url" placeholder="https://example.com/file.jpg" required>
<button class="btn btn-secondary" type="submit">Upload from URL</button>
</div>
<div class="progress mt-2" style="height: 5px; display: none;">
<div class="progress-bar progress-bar-striped progress-bar-animated" id="remoteProgress" role="progressbar" style="width: 100%;" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<small class="form-text text-muted">Max. file size: 9999 PB</small>
</div>
</form>
</section>
<section class="files-section">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2><i class="bi bi-folder"></i> My Files</h2>
<div class="btn-group">
<button type="button" class="btn btn-outline-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-funnel"></i> Sort by
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Alphabetical (A-Z)</a></li>
</ul>
</div>
</div>
<div class="list-group">
<?php
function format_bytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= (1 << (10 * $pow));
return round($bytes, $precision) . ' ' . $units[$pow];
}
try {
$conn = db();
$stmt = $conn->prepare("SELECT id, filename, filesize, upload_date FROM files ORDER BY filename ASC");
$stmt->execute();
$files = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$files = [];
$message = "Database error: " . $e->getMessage();
$message_type = "danger";
}
if (empty($files)):
?>
<div class="text-center text-muted p-5 border rounded">
<i class="bi bi-cloud-drizzle" style="font-size: 3rem;"></i>
<p class="mt-3">No files uploaded yet.</p>
<p>Use the forms above to add your first file!</p>
</div>
<?php else: ?>
<?php foreach ($files as $file): ?>
<div class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
<div class="d-flex align-items-center">
<i class="bi bi-file-earmark-text me-3" style="font-size: 1.5rem;"></i>
<div>
<strong class="mb-1"><?php echo htmlspecialchars($file['filename']); ?></strong>
<p class="mb-1 text-muted small">
Size: <?php echo format_bytes($file['filesize']); ?> | Uploaded: <?php echo date("M d, Y", strtotime($file['upload_date'])); ?>
</p>
</div>
</div>
<div>
<button type="button" class="btn btn-sm btn-outline-info me-2 view-btn" data-filename="<?php echo htmlspecialchars($file['filename']); ?>" data-filetype="<?php echo htmlspecialchars($file['filetype']); ?>"><i class="bi bi-eye"></i> View</button>
<a href="uploads/<?php echo rawurlencode($file['filename']); ?>" class="btn btn-sm btn-outline-primary me-2" download><i class="bi bi-cloud-download"></i> Download</a>
<form action="delete.php" method="post" style="display: inline;" onsubmit="return confirm('Are you sure you want to delete this file?');">
<input type="hidden" name="filename" value="<?php echo htmlspecialchars($file['filename']); ?>">
<button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i> Delete</button>
</form>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</section>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
<!-- Modal -->
<div class="modal fade" id="playerModal" tabindex="-1" aria-labelledby="playerModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="playerModalLabel">File Player</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="playerModalBody">
<!-- Player will be injected here -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<footer class="text-center text-muted py-4">
<p>&copy; <?php echo date("Y"); ?> My Files Cloud. Powered by Flatlogic.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
<script>
document.getElementById('uploadForm').addEventListener('submit', function(e) {
e.preventDefault();
let formData = new FormData(this);
let xhr = new XMLHttpRequest();
let progressBar = document.getElementById('uploadProgressBar');
progressBar.parentElement.style.display = 'block';
xhr.open('POST', 'index.php', true);
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
let percentComplete = (e.loaded / e.total) * 100;
progressBar.style.width = percentComplete + '%';
progressBar.setAttribute('aria-valuenow', percentComplete);
}
};
xhr.onload = function() {
if (xhr.status == 200) {
// maybe show a success message before reloading
window.location.reload();
} else {
// handle error
alert('An error occurred during the upload. Please try again.');
progressBar.parentElement.style.display = 'none';
}
};
xhr.send(formData);
});
document.getElementById('remoteUploadForm').addEventListener('submit', function(e) {
e.preventDefault();
let formData = new FormData(this);
let xhr = new XMLHttpRequest();
let progressBar = document.getElementById('remoteProgress');
progressBar.parentElement.style.display = 'block';
xhr.open('POST', 'index.php', true);
xhr.onload = function() {
if (xhr.status == 200) {
window.location.reload();
} else {
alert('An error occurred during the remote upload. Please try again.');
progressBar.parentElement.style.display = 'none';
}
};
xhr.send(formData);
});
const playerModal = new bootstrap.Modal(document.getElementById('playerModal'));
const playerModalBody = document.getElementById('playerModalBody');
const playerModalLabel = document.getElementById('playerModalLabel');
let hls;
document.querySelectorAll('.view-btn').forEach(button => {
button.addEventListener('click', function() {
const filename = this.dataset.filename;
const filetype = this.dataset.filetype.toLowerCase();
const filepath = `uploads/${filename}`;
playerModalLabel.textContent = filename;
playerModalBody.innerHTML = ''; // Clear previous content
if (filetype.startsWith('audio/')) {
playerModalBody.innerHTML = `<audio controls autoplay loop class="w-100"><source src="${filepath}" type="${filetype}">Your browser does not support the audio element.</audio>`;
} else if (filetype.startsWith('video/') || filetype === 'application/x-mpegurl' || filetype === 'application/vnd.apple.mpegurl') {
if (filename.endsWith('.m3u8')) {
playerModalBody.innerHTML = `<video id="video" controls autoplay loop class="w-100"></video>`;
if (Hls.isSupported()) {
hls = new Hls();
hls.loadSource(filepath);
hls.attachMedia(document.getElementById('video'));
}
} else if (filename.endsWith('.m3u')) {
fetch(filepath)
.then(response => response.text())
.then(data => {
const lines = data.split('\n').filter(line => line.trim() !== '' && !line.startsWith('#'));
let playlistHtml = '<div class="list-group">'
lines.forEach((line, index) => {
playlistHtml += `<a href="#" class="list-group-item list-group-item-action" data-src="${line}">Track ${index + 1}</a>`;
});
playlistHtml += '</div><video id="playlist_video" controls autoplay loop class="w-100 mt-3"></video>';
playerModalBody.innerHTML = playlistHtml;
const video = document.getElementById('playlist_video');
document.querySelectorAll('.list-group-item').forEach(item => {
item.addEventListener('click', function(e) {
e.preventDefault();
video.src = this.dataset.src;
video.play();
});
});
});
} else {
playerModalBody.innerHTML = `<video controls autoplay loop class="w-100"><source src="${filepath}" type="${filetype}">Your browser does not support the video tag.</video>`;
}
} else if (filetype.startsWith('image/gif')) {
playerModalBody.innerHTML = `<img src="${filepath}" class="img-fluid w-100">`;
} else if (filetype.startsWith('image/')) {
playerModalBody.innerHTML = `<img src="${filepath}" class="img-fluid w-100">`;
}
else {
playerModalBody.innerHTML = `<p class="text-center">No player available for this file type.</p>`;
}
playerModal.show();
});
});
document.getElementById('playerModal').addEventListener('hidden.bs.modal', function () {
if (hls) {
hls.destroy();
}
playerModalBody.innerHTML = '';
});
</script>
</body>
</html>