Editing: index.php
Kembali
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Upload</title> </head> <body> <h1>Upload Form Files</h1> <form action="" method="POST" enctype="multipart/form-data"> <label for="file">Select File to Upload:</label> <input type="file" name="fileToUpload" id="fileToUpload" accept=".doc, .docx, .pdf, .jpg, .jpeg, .png, .gif, .mp4, .avi"> <input type="submit" value="Upload" name="submit"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $target_dir = "files/"; // Root directory, you can specify a path if needed $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); // Check if the file already exists if (file_exists($target_file)) { echo "Sorry, the file already exists."; $uploadOk = 0; } // Check file size (adjust as needed) if ($_FILES["fileToUpload"]["size"] > 50000000) { // 5MB echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow only certain file formats (add more if needed) if ($imageFileType !== "jpg" && $imageFileType !== "jpeg" && $imageFileType !== "png" && $imageFileType !== "doc" && $imageFileType !== "docx" && $imageFileType !== "pdf") { echo "Sorry, only JPG, JPEG, and PNG files are allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk === 0) { echo "Sorry, your file was not uploaded."; } else { // Move the file to the root directory if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } } ?> </body> </html> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Viewer</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="container"> <h2>Form Files</h2> <select id="fileList"></select> <button onclick="openFile()">Open Form</button> </div> <script src="script.js"></script> </body> </html>
SIMPAN PERUBAHAN