From 2c882d18a428720ee9447976f34561b75ebe45d2 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Thu, 20 Nov 2025 12:08:26 +0000 Subject: [PATCH] Auto commit: 2025-11-20T12:08:26.355Z --- assets/css/custom.css | 68 ++++++++++++ assets/js/main.js | 105 ++++++++++++++++++ index.php | 249 ++++++++++++++++++------------------------ upload.php | 54 +++++++++ 4 files changed, 331 insertions(+), 145 deletions(-) create mode 100644 assets/css/custom.css create mode 100644 assets/js/main.js create mode 100644 upload.php diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..44d4ae0 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,68 @@ +body { + font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; + background-color: #F8F9FA; +} + +.navbar-brand { + font-weight: 600; +} + +.hero { + background: linear-gradient(135deg, #0D6EFD, #4D8BF2); + color: white; + padding: 4rem 0; + text-align: center; +} + +.hero h1 { + font-weight: 700; + font-size: 3rem; +} + +.translation-box { + background-color: #FFFFFF; + border-radius: 0.5rem; + padding: 2rem; + box-shadow: 0 4px 12px rgba(0,0,0,0.05); +} + +.form-label { + font-weight: 500; +} + +.btn-primary { + background-color: #0D6EFD; + border-color: #0D6EFD; + padding: 0.75rem 1.5rem; + font-weight: 500; +} + +.btn-primary:hover { + background-color: #0b5ed7; + border-color: #0a58ca; +} + +.custom-file-upload { + border: 2px dashed #0D6EFD; + border-radius: 0.375rem; + padding: 2rem; + text-align: center; + cursor: pointer; + background-color: #f8f9fa; + transition: background-color 0.2s; +} + +.custom-file-upload:hover { + background-color: #e9ecef; +} + +#file-upload-filename { + margin-top: 1rem; + font-style: italic; + color: #6c757d; +} + +#processing-message { + display: none; + margin-top: 1.5rem; +} \ No newline at end of file diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..029c066 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,105 @@ +document.addEventListener('DOMContentLoaded', function () { + const fileUploadInput = document.getElementById('document-upload'); + const fileUploadLabel = document.querySelector('.custom-file-upload'); + const fileNameDisplay = document.getElementById('file-upload-filename'); + const translateBtn = document.getElementById('translate-btn'); + const processingMessage = document.getElementById('processing-message'); + + // Trigger file input click when the custom upload area is clicked + if(fileUploadLabel) { + fileUploadLabel.addEventListener('click', () => { + if(fileUploadInput) { + fileUploadInput.click(); + } + }); + } + + // Update UI when a file is selected + if(fileUploadInput) { + fileUploadInput.addEventListener('change', () => { + if (fileUploadInput.files.length > 0) { + const fileName = fileUploadInput.files[0].name; + if(fileNameDisplay) { + fileNameDisplay.textContent = `Selected file: ${fileName}`; + } + if(translateBtn) { + translateBtn.disabled = false; + } + } else { + if(fileNameDisplay) { + fileNameDisplay.textContent = ''; + } + if(translateBtn) { + translateBtn.disabled = true; + } + } + }); + } + + // Handle form submission + const translationForm = document.getElementById('translation-form'); + if(translationForm) { + translationForm.addEventListener('submit', function(e) { + e.preventDefault(); + + const formData = new FormData(); + formData.append('document', fileUploadInput.files[0]); + formData.append('source-lang', document.getElementById('source-lang').value); + formData.append('target-lang', document.getElementById('target-lang').value); + + const responseMessageDiv = document.getElementById('response-message'); + + if(processingMessage) { + processingMessage.style.display = 'block'; + } + if(responseMessageDiv){ + responseMessageDiv.innerHTML = ''; + responseMessageDiv.style.display = 'none'; + } + + if(translateBtn) { + translateBtn.disabled = true; + translateBtn.innerHTML = ' Translating...'; + } + + fetch('upload.php', { + method: 'POST', + body: formData + }) + .then(response => { + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return response.json(); + }) + .then(data => { + if(processingMessage) { + processingMessage.style.display = 'none'; + } + if(responseMessageDiv){ + const alertClass = data.status === 'success' ? 'alert-success' : 'alert-danger'; + responseMessageDiv.innerHTML = ``; + responseMessageDiv.style.display = 'block'; + } + if(translateBtn) { + translateBtn.disabled = false; + translateBtn.innerHTML = 'Translate'; + } + }) + .catch(error => { + if(processingMessage) { + processingMessage.style.display = 'none'; + } + if(responseMessageDiv){ + responseMessageDiv.innerHTML = ``; + responseMessageDiv.style.display = 'block'; + } + if(translateBtn) { + translateBtn.disabled = false; + translateBtn.innerHTML = 'Translate'; + } + console.error('Error:', error); + }); + }); + } +}); \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..52d8f2c 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,109 @@ - - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + easyenglishtranslator + + + + + + + + + + + + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- + + + +
+
+

Document Translation Made Simple

+

Upload a PDF or image, select your languages, and let our AI do the rest.

+
+
+ +
+
+
+
+
+
+ +
+ +

Click to browse or drag & drop your file here

+

(PDF, JPG, PNG, TIFF)

+
+ +
+
+ +
+
+ + +
+
+ + +
+
+ +
+ +
+
+
+ +
+
+
+
+ + + + + - + \ No newline at end of file diff --git a/upload.php b/upload.php new file mode 100644 index 0000000..26c118b --- /dev/null +++ b/upload.php @@ -0,0 +1,54 @@ + $status, + 'message' => $message, + 'data' => $data + ]); + exit; +} + +if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + json_response('error', 'Invalid request method.'); +} + +if (!isset($_FILES['document']) || $_FILES['document']['error'] == UPLOAD_ERR_NO_FILE) { + json_response('error', 'No file was uploaded.'); +} + +$file = $_FILES['document']; + +// Check for upload errors +if ($file['error'] !== UPLOAD_ERR_OK) { + $upload_errors = [ + UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', + UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', + UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded.', + UPLOAD_ERR_NO_FILE => 'No file was uploaded.', + UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.', + UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.', + UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.', + ]; + $error_message = $upload_errors[$file['error']] ?? 'Unknown upload error.'; + json_response('error', $error_message); +} + +$upload_dir = __DIR__ . '/uploads/'; +if (!is_dir($upload_dir)) { + if (!mkdir($upload_dir, 0775, true)) { + json_response('error', 'Failed to create upload directory.'); + } +} + +$file_name = basename($file['name']); +$target_path = $upload_dir . $file_name; + +// Move the file to the uploads directory +if (move_uploaded_file($file['tmp_name'], $target_path)) { + json_response('success', 'File uploaded successfully.', ['filePath' => 'uploads/' . $file_name]); +} else { + json_response('error', 'Failed to move uploaded file.'); +} +?> \ No newline at end of file