D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home5
/
rakcha
/
public_html
/
admin
/
Filename :
test.php
back
Copy
<?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>