<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Code Editor</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; background-color: #f4f4f4; text-align: center; } .container { max-width: 800px; margin: 50px auto; background: white; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } textarea { width: 100%; height: 400px; font-family: monospace; white-space: pre; } button { margin: 10px; padding: 10px; font-size: 16px; cursor: pointer; } </style> </head> <body> <div class="container"> <h1>Paste Your Code Here</h1> <textarea id="codeArea"></textarea> <br> <button onclick="editCode()">Edit</button> <button onclick="deleteCode()">Delete</button> <button onclick="pasteCode()">Paste</button> <button onclick="addCode()">Add</button> <button onclick="saveCode()">Save</button> </div> <script> function editCode() { let codeArea = document.getElementById("codeArea"); codeArea.removeAttribute("readonly"); codeArea.focus(); } function deleteCode() { if (confirm("Are you sure you want to delete the content?")) { document.getElementById("codeArea").value = ""; } } async function pasteCode() { try { const text = await navigator.clipboard.readText(); document.getElementById("codeArea").value += text; } catch (err) { alert("Failed to paste. Please allow clipboard access."); } } function addCode() { let newText = prompt("Enter the text you want to add:"); if (newText !== null) { document.getElementById("codeArea").value += "\n" + newText; } } function saveCode() { const codeContent = document.getElementById("codeArea").value; const formData = new FormData(); formData.append("code", codeContent); fetch('save_file.php', { method: 'POST', body: formData }) .then(response => response.text()) .then(data => { alert(data); }) .catch(error => { alert('Error saving file: ' + error); }); } </script> </body> </html>
save_file.php
<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { if (isset($_POST['code'])) { $code = $_POST['code']; $file = fopen('FILE.txt', 'w'); // Open the file in write mode if ($file) { fwrite($file, $code); // Write code to the file fclose($file); // Close the file echo "File has been saved as FILE.txt"; } else { echo "Failed to save the file."; } } else { echo "No code provided."; } } else { echo "Invalid request."; } ?>