Home >Backend Development >PHP Problem >How to delete uploaded files in php

How to delete uploaded files in php

藏色散人
藏色散人Original
2020-08-26 09:07:172775browse

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.

How to delete uploaded files in php

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=&#39;".$purl."&#39;";    //从数据库中删除图片文件
$delete = mysql_query($str);
if($delete)
{
unlink($file_delete);    //从自己写入的路径删除图片文件
echo "<script>alert(&#39;图片信息删除成功!&#39;);window.location.href=&#39;picture_manage.php&#39;</script>";
}
else
{
//echo $str;
echo "<script>alert(&#39;图片信息删除失败!&#39;);window.location.href=&#39;picture_manage.php&#39;</script>";
}
}
else
{
echo "<script>alert(&#39;请选择要删除的图片信息!&#39;);window.location.href=&#39;picture_manage.php&#39;</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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn