How to delete the generated HTML static page in the PHP article system

Source: Internet
Author: User
Keywords PHP Delete Article
Tags be deleted delete deleted deleting file files how to html

Absrtact: Generate HTML static pages when adding articles, but if you want to delete articles, the HTML static pages generated when you add articles should also be deleted, otherwise they become redundant files, so we should delete the unused articles while deleting the generated

HTML static pages are generated when you add an article, but if you want to delete an article, the HTML static page generated when you add the article should also be deleted, otherwise it becomes a redundant file, so we should delete the useless article while deleting 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 a 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");

?>

These codes are relatively easy to understand, Ob_start (), opening caching, Require_coce (". /conn.php "); Contains the database connection file, the following variable ID, $path are received from the page, the two values are passed over the list page, and then down to execute the SQL DELETE statement, the database inside the article to delete, The following if statement is an important judgment statement to delete a static page, and if $path exists, remove it with unlink. The while statement here is a read directory and does not need to be understood in depth.

A perfect article generation of HTML static page system should be, add the article while generating static HTML file, update the article also update the generated HTML static page, delete the generated HTML static page deleted at the same time, update the static page to regenerate the site is not introduced here, With the addition of the article is a truth, is to judge the $path of the article, and then the corresponding regeneration on the line, but to the static file write permission, otherwise update, delete static HTML article also want to give full permission, otherwise it will be wrong.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.