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:
- <? Php
- Functiondeletedir ($ dir ){
- If (! Handle = @ opendir ($ dir) {// check whether the directory to be opened exists
- Die ("this directory is not available ");
- }
- While (false! ==( $ File = readdir ($ handle ))){
- If ($ file! = "." & $ File! = "..") {// Exclude the current directory and parent directory
- $ File = $ dir. DIRECTORY_SEPARATOR. $ file;
- If (is_dir ($ file )){
- Deletedir ($ file );
- } Else {
- If (@ unlink ($ file )){
- Echo "file$ FileDeleted successfully.
";
- } Else {
- Echo "file$ FileDeletion failed!
";
- }
- }
- }
- If (@ rmdir ($ dir )){
- Echo "directory$ DirDeleted successfully.
N ";
- } Else {
- Echo "directory$ DirDeletion failed!
N ";
- }
- }
- // Test the program
- $ Dir = "/var/www/test ";
- Deletedir ($ dir );
- ?>
Create a write folder and file test in the/var/www/test folder
- shell>touchaaa
- shell>touchbbb
- shell>touchccc
- shell>toucheee
- shell>touchffff
- shell>mkdir111
- shell>mkdir222
- shell>mkdir333
Create and write files in the 111,222,333 folder, and then grant them permissions.
- 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...