PHP function rmdir () tips _ PHP Tutorial

Source: Internet
Author: User
Explains how to use the PHP function rmdir. In PHP, there are many functions for programming, and their functions are also very powerful. Today we will introduce to you that PHP is a type of function embedded in HTML and server in PHP. There are many functions for programming, and their functions are also very powerful. What we will introduce to you todayPHP is a scripting language embedded in HTML and interpreted by the server. It can be used to manage dynamic content, support databases, process session tracking, and even build the entire e-commerce site. It supports many popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server. Why is dynamic content so popular? Assume that you are managing e-commerce sites with 10 products. As long as the product does not change frequently or is not expected to change much, it is not difficult to manually compile 10 static product pages with necessary information, forms, and such content. However, assume that you want to add 10 more products this month, and then add more products next month. The price may change sometimes or you want to change the site View. Then you will be in the predicament of manually writing dozens of pages, maybe hundreds of static pages.

On the other hand, assume that you start from creating the product. php page. It does not have static information. Instead, it can be encoded to extract information from the product database and dynamically build a page. Then you have a metadata page that provides one, one hundred, or even 100,000 separate pages based on the information stored in the database. Now, the website administrator no longer simply updates static pages all day, because the information in the company database can be updated at the same time. This eliminates the headache of time delay (the interval between changing information in the database and displaying information on the website ). Next we will look at an example of Recursive directory deletion in PHP, hoping to help you.

The PHP function rmdir () can be done, but to delete a non-empty directory, you cannot quickly delete it. you must first delete the files in the directory, however, there may be subdirectories in the directory, so we need to recursively delete the Directory in PHP:

PHP recursively deletes the directory code:

 
 
  1. <? Php
  2. Functiondeletedir ($ dir ){
  3. If (! Handle = @ opendir ($ dir) {// check whether the directory to be opened exists
  4. Die ("this directory is not available ");
  5. }
  6. While (false! ==( $ File = readdir ($ handle ))){
  7. If ($ file! = "." & $ File! = "..") {// Exclude the current directory and parent directory
  8. $ File = $ dir. DIRECTORY_SEPARATOR. $ file;
  9. If (is_dir ($ file )){
  10. Deletedir ($ file );
  11. } Else {
  12. If (@ unlink ($ file )){
  13. Echo "file$ FileDeleted successfully.
    ";
  14. } Else {
  15. Echo "file$ FileDeletion failed!
    ";
  16. }
  17. }
  18. }
  19. If (@ rmdir ($ dir )){
  20. Echo "directory$ DirDeleted successfully.
    N ";
  21. } Else {
  22. Echo "directory$ DirDeletion failed!
    N ";
  23. }
  24. }
  25. // Test the program
  26. $ Dir = "/var/www/test ";
  27. Deletedir ($ dir );
  28. ?>

Create a write folder and file test in the/var/www/test folder

 
 
  1. shell>touchaaa
  2. shell>touchbbb
  3. shell>touchccc
  4. shell>toucheee
  5. shell>touchffff
  6. shell>mkdir111
  7. shell>mkdir222
  8. shell>mkdir333

Create and write files in the 111,222,333 folder, and then grant them permissions.

 
 
  1. shell>chown[url]www.www[/url]test-R

The above are the specific methods and test results for PHP to recursively delete directories using the rmdir () function for your reference.


Bytes. We will introduce to you today that PHP is embedded in HTML and server...

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.