34329-vm/upload.php
Flatlogic Bot a7265cf7d7 0.1
2025-09-24 04:05:20 +00:00

93 lines
4.0 KiB
PHP

<?php
// Basic security check
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo "Method Not Allowed";
exit;
}
$uploadDir = 'uploads/';
$response = [
'success' => false,
'message' => 'An unknown error occurred.'
];
if (isset($_FILES['fileUpload']) && $_FILES['fileUpload']['error'] === UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['fileUpload']['tmp_name'];
$fileName = $_FILES['fileUpload']['name'];
$fileSize = $_FILES['fileUpload']['size'];
$fileType = $_FILES['fileUpload']['type'];
$fileNameCmps = explode(".", $fileName);
$fileExtension = strtolower(end($fileNameCmps));
// Sanitize file name
$newFileName = md5(time() . $fileName) . '.' . $fileExtension;
$destPath = $uploadDir . $newFileName;
// Check if file is allowed
$allowedfileExtensions = ['pdf', 'doc', 'docx', 'jpg', 'jpeg', 'png'];
if (in_array($fileExtension, $allowedfileExtensions)) {
if(move_uploaded_file($fileTmpPath, $destPath)) {
$response['success'] = true;
// In a real app, you would save this info to the database
$response['message'] = "File uploaded successfully!";
$response['data'] = [
'original_name' => htmlspecialchars($fileName),
'new_name' => $newFileName,
'path' => $destPath,
'print_options' => [
'location' => htmlspecialchars($_POST['location'] ?? 'N/A'),
'color' => htmlspecialchars($_POST['color'] ?? 'N/A'),
'sides' => htmlspecialchars($_POST['sides'] ?? 'N/A'),
'paper_size' => htmlspecialchars($_POST['paperSize'] ?? 'N/A'),
'orientation' => htmlspecialchars($_POST['orientation'] ?? 'N/A'),
]
];
} else {
$response['message'] = 'There was some error moving the file to upload directory.';
}
} else {
$response['message'] = 'Upload failed. Allowed file types: ' . implode(', ', $allowedfileExtensions);
}
} else {
$response['message'] = 'Error uploading file. Error code: ' . $_FILES['fileUpload']['error'];
}
// For demonstration, we'll just print the response.
// In a real app, you might redirect with a status message.
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Status</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<div class="container mt-5">
<div class="card shadow-sm">
<div class="card-body text-center">
<h1 class="card-title"><?= $response['success'] ? '✅ Success' : '❌ Error' ?></h1>
<p class="lead"><?= htmlspecialchars($response['message']) ?></p>
<?php if ($response['success']): ?>
<div class="alert alert-info text-start">
<h5>Order Details:</h5>
<p><strong>File:</strong> <?= $response['data']['original_name'] ?></p>
<p><strong>Location:</strong> <?= $response['data']['print_options']['location'] ?></p>
<p><strong>Color:</strong> <?= $response['data']['print_options']['color'] ?></p>
<p><strong>Sides:</strong> <?= $response['data']['print_options']['sides'] ?></p>
<p><strong>Paper Size:</strong> <?= $response['data']['print_options']['paper_size'] ?></p>
<p><strong>Orientation:</strong> <?= $response['data']['print_options']['orientation'] ?></p>
<hr>
<p class="text-muted small">Next step would be to calculate the bill and proceed to payment.</p>
</div>
<?php endif; ?>
<a href="index.php" class="btn btn-primary-custom mt-3">Return to Dashboard</a>
</div>
</div>
</div>
</body>
</html>