Server IP : 144.76.124.212 / Your IP : 216.73.216.138 Web Server : LiteSpeed System : Linux l4cp.vnetindia.com 4.18.0-553.40.1.lve.el8.x86_64 #1 SMP Wed Feb 12 18:54:57 UTC 2025 x86_64 User : rakcha ( 1356) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home5/rakcha/public_html/admin/ |
Upload File : |
<?php session_start(); include("includes/database.php"); // Handle form submission if ($_SERVER['REQUEST_METHOD'] == 'POST') { $conn = new mysqli($host, $user, $pass, $db); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $type = $_POST['file_type']; // image or video $desc = $_POST['description']; // text input $targetDir = $type == "image" ? "galleryImage/" : "galleryVideo/"; $file = $_FILES['media_file']; $fileName = basename($file['name']); $targetFilePath = $targetDir . $fileName; if (move_uploaded_file($file['tmp_name'], $targetFilePath)) { $stmt = $conn->prepare("INSERT INTO gallery (filename, type, description) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $fileName, $type, $desc); if ($stmt->execute()) { $message = "File uploaded and saved to database successfully!"; } else { $message = "Database insert failed."; } $stmt->close(); } else { $message = "File upload failed."; } $conn->close(); } ?> <!DOCTYPE html> <html> <head> <title>Upload Image or Video</title> </head> <body> <h2>Upload Image or Video</h2> <?php if (!empty($message)): ?> <p style="color: green;"><?php echo $message; ?></p> <?php endif; ?> <form method="POST" enctype="multipart/form-data"> <label>Select File Type:</label><br> <input type="radio" name="file_type" value="image" required> Image <input type="radio" name="file_type" value="video" required> Video <br><br> <label>Select File:</label><br> <input type="file" name="media_file" accept="image/*,video/*" required><br><br> <label>Description:</label><br> <input type="text" name="description" placeholder="Enter description" required><br><br> <input type="submit" value="Upload"> </form> </body> </html>