PHP deletes the generated HTML page while deleting the article _php tutorial

Source: Internet
Author: User
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 ...

  • 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.