This article mainly introduces the method of deleting files through PHP recursive traversal. It involves the related skills of PHP traversal file operation. It is of great practical value. Friends in need can refer to it.
The example of this article tells about PHP recursive traversal. How to delete files. The details are as follows:
With slight modifications, this function can be turned into a recursive file copy function
<?php function mover($src,$dst) { $handle=opendir($src); // Opens source dir. if (!is_dir($dst)) mkdir($dst,0755); // Make dest dir. while ($file = readdir($handle)) { if (($file!=".") and ($file!="..")) { // Skips . and .. dirs $srcm=$src."/".$file; $dstm=$dst."/".$file; if (is_dir($srcm)) { // If another dir is found mover($srcm,$dstm); // calls itself - recursive WTG } else { copy($srcm,$dstm); unlink($srcm); // Is just a copy procedure is needed } // comment out this line } } closedir($handle); rmdir($src); } ?>
Summary: The above is the entire content of this article, I hope it can be helpful to Everyone’s learning helps.
Related recommendations:
Implement array generation in php to generate sql statements to be executed
php for file operations And the method of string encryption
The addition, deletion, modification and query function implemented by mysql in php
The above is the detailed content of PHP recursive function traverses the method of deleting files. For more information, please follow other related articles on the PHP Chinese website!