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/www/ |
Upload File : |
<?php session_start(); // ✅ Session check must come AFTER session_start if (!isset($_SESSION['admin_name'])) { header("location: index.php"); exit; } // ✅ Database connection $host = "localhost"; $user = "rakcha_db"; $pass = "rakcha_db"; $db = "rakcha_db"; $con = new mysqli($host, $user, $pass, $db); if ($con->connect_error) { die("Connection failed: " . $con->connect_error); } // ✅ Handle form submission $message = ""; if (isset($_POST['add']) && $_POST['add'] === 'Upload') { $type = $_POST['file_type']; // image or video $desc = $_POST['description']; // text input $file = $_FILES['media_file']; // Choose upload directory $targetDir = ($type == "image") ? "galleryImage/" : "galleryVideo/"; $fileName = basename($file['name']); $targetFilePath = $targetDir . $fileName; // Upload file if (move_uploaded_file($file['tmp_name'], $targetFilePath)) { // Save to DB $stmt = $con->prepare("INSERT INTO gallery2 (filename, type, description) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $fileName, $type, $desc); if ($stmt->execute()) { $message = "✅ File uploaded and saved to database successfully!"; } else { $message = "❌ Failed to insert data into the database."; } $stmt->close(); } else { $message = "❌ File upload failed."; } } ?> <!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" name="add"> </form> </body> </html>