PHP deletes the generated HTML page when deleting an article _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP also deletes the generated HTML page when deleting an article. HTML static pages are generated when you add an article. if you want to delete an article, the HTML static pages generated when you add the article should also be deleted at the same time. Otherwise, the HTML static pages become redundant files, therefore, we should generate an HTML static page when adding an article, but if we want to delete the article, the HTML static page generated when adding the article should also be deleted at the same time, otherwise it will become a redundant file, therefore, when deleting useless articles, we should delete the generated HTML static pages at the same time. let's take a look at how to delete the generated HTML static pages in the PHP article system at the same time, here is just a simple principle system, which can be used as a reference. more mature systems can refer to more mature CMS systems. below is the source code 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 easy to understand, ob_start (); enable cache, require_coce (".. /conn. php "); contains the database connection file. the following changes $ id and $ path are all accepted transfer pages. These two values are passed in the list page, next, execute the SQL deletion statement to delete the articles in the database. the next if statement is an important judgment statement for deleting static pages. if $ path exists, delete the file with unlink. The while statement here is the directory to be read and does not need to be understood in depth.

A complete HTML static page generation system should be: static HTML files are generated when an article is added, and HTML static pages generated when the article is updated at the same time, when deleting an HTML static page, the generated HTML static page is deleted at the same time. This is not described here when a static page is re-generated during the update. it is the same principle as adding an article, that is, judging the $ path of the article, next, refresh the achievement line, but grant the permission to write to the static file. Otherwise, the update will fail and the permission is required to delete the static HTML article. Otherwise, an error will occur.

This article was originally posted at http://www.60ie.net/article/5/248.html.

...

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.