php 不依赖数据实现删除图片,核心代码

<?php 
$file = "ueditorphpuploadimage**.png";
foreach (glob("$file") as $filename) 
{
echo "<img src="".$filename."">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<form name='input' action='' method='post'>";
//echo "目标文件夹路径:<input type='text' name='dir' value='$file'/>"; //出错的原因在于$file,而是$filename
echo "<input type='text' name='dir' value='$filename'>"; //type='submit'的话不会post出值的。。。
echo "<input type='submit' value='删除' />";
echo "</form>";
}
?> 

<?php
error_reporting(0); 
$yourpost=$_POST['dir'];
echo $yourpost;
?>

<?php
$file = $_POST['dir'];
unlink($file)
?>

 加后缀

<?php 
$img = array('gif','png','jpg');//所有图片的后缀名
$dir = 'ueditorphpuploadimage**.'; 
foreach($img as $k=>$v)//$img是数组 $_k是键 $_v是值 这是一种遍历数组的简便方法 那个变量代表k/v对的中的key,那个变量可以用来表示value
{
    $file = $dir.$v;
    foreach (glob("$file") as $filename) 
 {
     echo "<img src="".$filename."">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
     echo "<form name='input' action='' method='post'>";
     //echo "目标文件夹路径:<input type='text' name='dir' value='$file'/>"; //出错的原因在于$file,而是$filename 
     echo "<input type='text' name='dir' value='$filename'>"; //type='submit'的话不会post出值的。。。
     echo "<input type='submit' value='删除' />";
     echo "</form>";
 }
}
?> 

<?php
error_reporting(0); 
$yourpost=$_POST['dir'];
echo $yourpost;
?>

<?php
$file = $_POST['dir'];
unlink($file)
?>
原文地址:https://www.cnblogs.com/hellowzd/p/4124889.html