在php和mysql中处理一个小的图像库项目。这个项目有两个表。相册(albumid和albumname)和多媒体资料(id、imagename、albumid、img\u name)。因此,当用户需要创建一个图像库时,他们需要输入所有的信息,比如标题、专辑名和图像。我可以做大部分的部分,我被卡住的部分是插入下拉列表,在我的情况是专辑。这是我的add\u photo.php
<!--Adding Post Area-->
<form action="add_photo_check.php" method="POST" enctype="multipart/form-data">
<?php
if(isset($_SESSION['message']))
{
echo $_SESSION['message'];
unset($_SESSION['message']);
}
?>
<!--Form for post-->
<div class="form-group">
<label for="posttitle">
<h5>Photo Title</h5>
</label>
<textarea name="imageName" class="form-control" placeholder="photo title.." ></textarea>
</div>
<div class="form-group">
<label for="album">Select Album</label>
<select class="form-control" name="albumId" id="album">
<option>Select Album</option>
<?php
$sql = "select * from album";
$res = mysqli_query($conn,$sql);
while($row=mysqli_fetch_assoc($res)){
echo"<option value=\"" .$row['albumId'] . "\" >" .$row['albumName']."</option>\n";
}
?>
</select>
</div>
<div class="form-group">
<label for="uploadimage">
<h5>Upload image</h5>
</label>
<div class="btn">
<input type="file" name="image">
</div>
</div>
<input type="submit" value="Publish" name="publish" class="btn btn-primary">
</form>
</div>
这是我的函数文件add\u photo\u check.php
<?php
include "includes/header.php";
if(isset($_POST['publish']))
{
$title=$_POST['imageName'];
$title=mysqli_real_escape_string($conn,$imageName);
$title=htmlentities($imageName);
$id=$_POST['albumId'];
$id=mysqli_real_escape_string($conn,$albumId);
$id=htmlentities($albumId);
$uploadOk = 1;
$img_name = $_FILES['image']['name'];
$errorMessage = "";
if($img_name != "") {
$targetDir = "images/upload/";
$img_name = $targetDir . uniqid() . basename($img_name);
$imageFileType = pathinfo($img_name, PATHINFO_EXTENSION);
if(strtolower($imageFileType) != "jpeg" && strtolower($imageFileType) != "png" && strtolower($imageFileType) != "jpg") {
$_SESSION['message']="<div class='alert alert-danger'> Sorry, only jpeg, jpg and png files are allowed!</div>";
$uploadOk = 0;
}
if($_FILES['image']['size'] > 100000){
$_SESSION['message']="<div class='alert alert-danger'> Image is too big to upload!</div>";
header("Location: add_photo.php");
}
if($uploadOk) {
if(move_uploaded_file($_FILES['image']['tmp_name'], $img_name)) {
//image uploaded okay
}
$sql="insert into gallery (title, id, img_name) value('$imageName','$albumId', '$img_name')";
$res=mysqli_query($conn,$sql);
if($res)
{
$_SESSION['message']="<div class='alert alert-success'> Post Successfuly Published</div>";
header("Location: add_photo.php");
}
else
{
$_SESSION['message']="<div class='alert alert-danger'> Something went wrong!</div>";
header("Location: add_photo.php");
}
}
}
}
?>
任何帮助都将不胜感激。谢谢您。
暂无答案!
目前还没有任何答案,快来回答吧!