How can PHP be used to create an admin interface for a database of images uploaded via FTP?
To create an admin interface for a database of images uploaded via FTP using PHP, you can create a web application that allows administrators to view, add, edit, and delete images in the database. This can be achieved by connecting to the database, querying the images table, displaying the images in a user-friendly interface, and providing options for CRUD operations.
<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query the images table
$sql = "SELECT * FROM images";
$result = $conn->query($sql);
// Display the images in a user-friendly interface
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<img src='uploads/" . $row["image_name"] . "' alt='" . $row["image_alt"] . "'>";
echo "<a href='edit_image.php?id=" . $row["id"] . "'>Edit</a>";
echo "<a href='delete_image.php?id=" . $row["id"] . "'>Delete</a>";
}
} else {
echo "0 results";
}
$conn->close();
?>