Home > Article > Backend Development > How to delete uploaded files in php
How to delete uploaded files in php: first get the file saving path; then set the path information according to your own file directory; finally delete the image file from the database through the "DELETE" statement.
Recommended: "PHP Video Tutorial"
php file deletion
php file deletion only You need to use the unlink() function.
<?php /* 图片删除处理页 */ if($_GET["p_url"]) { $purl = $_GET["p_url"]; //获取文件保存路径 $file_delete = "../".$purl; //根据自己的文件目录设置路径信息 $str = "DELETE FROM picture WHERE p_url='".$purl."'"; //从数据库中删除图片文件 $delete = mysql_query($str); if($delete) { unlink($file_delete); //从自己写入的路径删除图片文件 echo "<script>alert('图片信息删除成功!');window.location.href='picture_manage.php'</script>"; } else { //echo $str; echo "<script>alert('图片信息删除失败!');window.location.href='picture_manage.php'</script>"; } } else { echo "<script>alert('请选择要删除的图片信息!');window.location.href='picture_manage.php'</script>"; } ?>
The above is the detailed content of How to delete uploaded files in php. For more information, please follow other related articles on the PHP Chinese website!