The HTML static page is generated when the article is added, but if you want to delete the article, the HTML static page generated when the article is added should be deleted at the same time, otherwise it becomes redundant file, so we should delete the useless article and delete the generated HTML static page. below to see how the PHP article system inside how to delete the generated HTML static page, here is just a simple principle system, can be used as a reference, more mature system can refer to the more mature CMS system, the following is the source file.
Ob_start ();
Require_once (".. /inc/conn.php ");
$id =$_get["id"];
$path =$_get["path"];
$sql = "Delete from newscontent where newsid= $id";
mysql_query ($sql);
if (File_exists (". /newslist/$path "))
{
Unlink (".. /newslist/$path ");
$foldername =substr ($path, 0,10);
$folder =fopen (". /newslist/$foldername ");
$n = 0;
while ($f =readdir ($folder))
{
if ($f <> "." && $f <> "...")
{
$n + +;
}
}
Closedir ();
if ($n ==0)
{
RmDir (".. /newslist/$foldername ");
}
}
Header ("location:del.php");
?>
This code is easier to understand, Ob_start (), turn on cache, Require_coce (".. /conn.php "), including the database connection file, the following variable $id, $path is to accept the page, the two values are passed in the list page, and then execute the SQL DELETE statement, the database in the first delete the article, the next The IF statement of a polygon is an important judgment statement to delete a static page, and if $path exists, it is deleted with unlink. The while statement here is the Read directory and does not need to be understood in depth.
A perfect article to generate HTML static pages of the system should be, add the article when the static HTML file, update the article at the same time to update the generated HTML static page, delete also deleted the generated HTML static page, the update when the static page regeneration is not introduced here, With the addition of the article is a reason, is to judge the $path of the article, and then the corresponding regeneration on the line, but to the static file write permissions, otherwise update, delete static HTML article also to give full permission, otherwise it will be wrong.
This article original from: http://www.60ie.net/article/5/248.html submission, reproduced please indicate the source.
http://www.bkjia.com/PHPjc/371898.html www.bkjia.com true http://www.bkjia.com/PHPjc/371898.html techarticle The HTML static page is generated when the article is added, but if you want to delete the article, the HTML static page generated when the article is added should be deleted at the same time, otherwise it becomes redundant file, so we should ...