我有一个功能,人们可以将图像上传到我的网站,但我希望他们提供标题,标签和描述。我为图像制作了模态。因此,如果用户单击图像,我希望他们看到标题,标签和描述,以及用户给出的图像。
我在朋友的帮助下尝试了一些东西,但我们都不知道它是如何工作的。有人的帮助我会很高兴。
这是我目前用于图像上传的内容
<?php
//Start connection to the localhost server
$conn = mysqli_connect("localhost", "root", "");
if ($conn) {
echo "<br />";
} else {
die("". mysqli_connect_error());
}
//Select Database
$selectalreadycreateddatabase = mysqli_select_db($conn, "uploaddisplay");
if ($selectalreadycreateddatabase) {
echo "<br />";
} else {
echo "<br />";
$createNewDb = "CREATE DATABASE IF NOT EXISTS `uploaddisplay`";
if (mysqli_query($conn, $createNewDb)) {
echo "<br />";
$selectCreatedDatabase = mysqli_select_db($conn, "uploaddisplay");
if ($selectCreatedDatabase) {
echo "<br />";
// Creating new table
$sqlcreatetable = "
CREATE TABLE IF NOT EXISTS `updis` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
";
if (mysqli_query($conn, $sqlcreatetable)) {
echo "<br />";
} else {
echo "<br />";
}
}
} else {
echo "<br />";
}
}
//If submit button is clicked
if(isset($_POST['fileuploadsubmit'])) {
$fileupload = $_FILES['fileupload']['name'];
$fileuploadTMP = $_FILES['fileupload']['tmp_name'];
//This is the folder where images will be saved.
$folder = "images/";
move_uploaded_file($fileuploadTMP, $folder.$fileupload);
//Insert image details into `updis` table
$sql = "INSERT INTO `updis`(`name`) VALUES ('$fileupload')";
$qry = mysqli_query($conn, $sql);
if ($qry) {
echo "<br />";
}
}
//Select all data from `updis` table
$select = " SELECT * FROM `updis` " ;
$query = mysqli_query($conn, $select) ;
while($row = mysqli_fetch_array($query)) {
$image = $row['name'];
//Display image from the database
echo '<img src="images/'.$image.'" height="300" width="300" >';
}
//close connection
if (mysqli_close($conn)) {
echo "<br />";
}
?>
这使我可以上传图片并将其保存在数据库中
表格:
<form method="post" action="" enctype="multipart/form-data"> <input type="file" name="fileupload"/> <input type="submit" name="fileuploadsubmit" value="Upload"/><br> </form> </div> <div class="modal-footer">
<form> <label for="name">Title</label>
<input type="text" id="name1" name="name" required>
</form>