Ask for advice. However, you cannot delete the original folder. You can only delete files. But you cannot delete the original folder. You can only delete files.
Reply content:
Ask for advice. But you cannot delete the original folder. You can only delete files.
The above are all linux Command lines. I provide a pure PHP code.
Delete all files in a directory in one sentence
array_map('unlink', glob('*'));
From stew-Research on web
Http://levi.cg.am/archives/3524
/**
* Delete A directory (including the following files)
* @ Return void
*/
Function del_directory ($ directory, $ subdir = true ){
If (is_dir ($ directory) = false ){
Exit ("The Directory Is Not Exist! ");
}
$ Handle = opendir ($ directory );
While ($ file = readdir ($ handle ))! = False ){
If ($ file! = "." & $ File! = ".."){
Is_dir ("$ directory/$ file ")?
Del_directory ("$ directory/$ file "):
Unlink ("$ directory/$ file ");
}
}
If (readdir ($ handle) = false ){
Closedir ($ handle );
Rmdir ($ directory );
}
}
/**
* Delete all files under the directory, but do not delete the Directory
* @ Return void
*/
Function del_directory_file ($ directory ){
If (is_dir ($ directory) = false ){
Exit ("The Directory Is Not Exist! ");
}
$ Handle = opendir ($ directory );
While ($ file = readdir ($ handle ))! = False ){
If ($ file! = "." & $ File! = ".." & Is_file ("$ directory/$ file ")){
Unlink ("$ directory/$ file ");
}
}
Closedir ($ handle );
}
Can I delete the folder and create a folder with the same name (you delete all files anyway, of course, you have to pay attention to the permission )? If not, read the following blog:
Http://cgxcn.blog.163.com/blog/static/13231242200931792027965/
Using more search engines, these questions are easily found on the internet, and there is no need to ask here.
Hum, he was also stepped on...
This kind of thing should not have been handed over to PHP... Why is it necessary to use the command line! N mausen