Php 从数据库中删除图像时,无法从文件夹中删除图像
我正在尝试从记录图像的数据库和文件夹中删除图像。这是我的密码。问题是,如果我提交删除查询,那么数据库映像将被删除,但文件夹映像仍然保留。请帮忙Php 从数据库中删除图像时,无法从文件夹中删除图像,php,html,mysql,arrays,image,Php,Html,Mysql,Arrays,Image,我正在尝试从记录图像的数据库和文件夹中删除图像。这是我的密码。问题是,如果我提交删除查询,那么数据库映像将被删除,但文件夹映像仍然保留。请帮忙 if(empty($_POST)===false) { if(empty($_POST['events'])===true||empty($_POST['description'])===true||empty($_FILES['images']['name'])) { ?>
if(empty($_POST)===false)
{
if(empty($_POST['events'])===true||empty($_POST['description'])===true||empty($_FILES['images']['name']))
{
?>
<div class="alert alert-warning alert-dismissible text-center" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>Add some events and descriptions
</div>
<?php
}
else
if (isset($_POST["events"])&&isset($_POST["description"]))
{
$event_title=$_POST["events"];
$description=$_POST["description"];
$filetmp=$_FILES["images"]["tmp_name"];
$filename=$_FILES["images"]["name"];
$filetype=$_FILES["images"]["type"];
$filepath= "photo1/".$filename;
move_uploaded_file( $filetmp,$filepath);
$data=array($page_id,$event_title,$description,$filepath);
$add=add_data_event($data);
if($add)
{
header('location:hotel1_galery_event.php?page_id=1 && msg=Add Offers Successfully');
}
foreach ($errors as $value)
{
echo $value;
}
}
}
if(isset($_GET['id']))
{
$id=$_GET['id'];
delete_event1($id);
unlink($_GET['file']);
header('location:hotel1_galery_event.php?page_id=1 && msg=Delete Successfully');
}
$data1=get_all_event($page_id);
?>
if(空($\u POST)==false)
{
如果(空($_POST['events'])==true | | |空($_POST['description'])==true | |空($_文件['images']['name']))
{
?>
添加一些事件和描述
HTML
<form action="hotel1_galery_event.php?page_id=1" method="post" class="col-sm-4" enctype="multipart/form-data">
<div class="form-group has-info">
<label class="control-label" for="inputSuccess">Event title</label>
<input type="text" class="form-control" name="events" id="events">
</div>
<div class="form-group has-info">
<label>Event Description</label>
<textarea id="description" name="description" placeholder="Event Description" class="form-control " rows="3"></textarea><br><br>
</div>
<div class="form-group has-info">
<label>Event Related images</label>
<input type="file" name="images"><br>
</div>
<button type="submit" class="btn btn-primary">
<span>SUBMIT</span>
</button>
</form>
</div>
</div>
</header>
<div>
<h2 class="text-center"> OUR NEW EVENTS.......</h2>
</div>
<div>
<table class="table table-striped table-bordered table-hover text-center">
<tr class="bg-default">
<th>EVENT TITLE</th>
<th>EVENT DESCRIPTION</th>
<th>EVENT RELATED IMAGES</th>
<th></th>
</tr>
<?php
foreach ($data1 as $val)
{
?>
<tr class="bg-default">
<td>
<?php
echo "<br>";
echo $val['event_title'];
?>
</td>
<td>
<?php
echo "<br>";
echo $val['event_description'];
?>
</td>
<td>
<?php
echo "<img border=\"0\" src=\"".$val['image_path']."\" width=\"102\" height=\"91\">";
?>
</td>
<td>
<a href="hotel1_galery_event.php?page_id=1&&id=<?php echo $val['event_id']; ?> && msg=Delete Successfully" >
<button type="submit" class="btn btn-primary">
<span> DELETE</span>
</button>
</a> 
<a href="hotel1_galery_eventedit.php?page_id=1&&id=<?php echo $val['event_id']; ?> && msg=Edit Successfully" >
<button type="submit" class="btn btn-primary">
<span> EDIT</span>
</button>
</a><br>
</td>
<?php
}
?>
</tr>
</table>
活动名称
事件描述
事件相关图像
提交
我们的新活动。。。。。。。
活动名称
事件描述
事件相关图像
 
在您的案例中,有两个选项可以删除图像
首先
发送url中包含完整路径的文件名,如下所示
<a href="hotel1_galery_event.php?page_id=1&&id=<?php echo $val['event_id']; ?> && msg=Delete Successfully &file=<?php echo $filepath ">
你在哪里传递这个值???取消链接($\u GET['file']);
?它将作为header移动到header位置('location:hotel1\u galery\u event.php?page\u id=1&&msg=Delete Successfully');我询问$\u GET['file']的值。
;这是一个图像文件路径,你在哪里传递它??