Sindbad~EG File Manager
<?php
// UpdateScreenshot.php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$dbFile = 'ThreeBodyDatabase.db';
$db = new SQLite3($dbFile);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the DocumentNumber from POST data.
if (!isset($_POST['DocumentNumber']) || empty($_POST['DocumentNumber'])) {
die("No document specified.");
}
$docId = (int) $_POST['DocumentNumber'];
// Check if a file was uploaded.
if (isset($_FILES['png_file']) && $_FILES['png_file']['error'] === UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['png_file']['tmp_name'];
$fileName = basename($_FILES['png_file']['name']);
$fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
// Allow only PNG.
if ($fileExtension !== "png") {
die("Error: Only PNG files are allowed.");
}
$check = getimagesize($fileTmpPath);
if ($check === false) {
die("Error: Uploaded file is not a valid image.");
}
// Set target folder.
$targetDir = "./images/";
if (!is_dir($targetDir)) {
mkdir($targetDir, 0755, true);
}
// Create a safe filename.
$newFileName = "doc_" . $docId . "_" . time() . "_" . preg_replace("/[^A-Za-z0-9_\-\.]/", '_', $fileName);
$targetFile = $targetDir . $newFileName;
if (!move_uploaded_file($fileTmpPath, $targetFile)) {
echo($targetFile);
die("Error: Could not move uploaded file.");
}
// Update the document record with the new png_filename.
$stmt = $db->prepare("UPDATE documents SET png_filename = :filename WHERE DocumentNumber = :docId");
$stmt->bindValue(':filename', $newFileName, SQLITE3_TEXT);
$stmt->bindValue(':docId', $docId, SQLITE3_INTEGER);
if (!$stmt->execute()) {
die("Error updating screenshot: " . $db->lastErrorMsg());
}
echo "Screenshot updated successfully for Document #{$docId}.";
} else {
die("No file uploaded or an error occurred.");
}
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Update Screenshot</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
label { display: block; margin-bottom: 8px; }
input[type="file"] { margin-bottom: 12px; }
button { padding: 8px 16px; background-color: #00008B; color: #fff; border: none; cursor: pointer; }
button:hover { background-color: #0000a0; }
</style>
</head>
<body>
<h1>Update Screenshot for Document</h1>
<form method="post" action="UpdateScreenshot.php" enctype="multipart/form-data">
<input type="hidden" name="DocumentNumber" value="<?php echo isset($_GET['doc']) ? (int)$_GET['doc'] : ''; ?>">
<label for="png_file">Select PNG File:</label>
<input type="file" name="png_file" id="png_file" accept="image/png" required>
<button type="submit">Update Screenshot</button>
</form>
<p><a href="BrowseThreeBody.php">Return to Browse</a></p>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists