php 删除图片原生代码

前端代码

<button> <a href="imageDel.php?imageName=<?php echo $file?>">删除</a> </button>

后端代码

//删除图片
$file = $_GET['imageName'];
if (file_exists($file)) {
    if (unlink($file)) {
        echo "<script> alert('删除成功');window.history.go(-1); </script>";
//        echo "<script> alert('删除成功');location.href= </script>";

    } else {
        echo $file . ' 删除失败!';
    }
} else {
    echo $file . ' 不存在!';
}

猜你喜欢

转载自blog.csdn.net/QiZong__BK/article/details/129751999