Three php file deletion codes
The code is as follows: |
Copy code |
If ($ od = opendir ($ d) // $ d is the directory name. { While ($ file = readdir ($ od ))! = False) // www.111cn.net reads files in the directory { Unlink ($ file); // $ file is the file name. } } To solve these three php functions: opendir () readdir () unlink () |
File deletion code 2 system call method
The code is as follows: |
Copy code |
Function del_dir ($ dir) { If (strtoupper (substr (php_ OS, 0, 3) = 'win '){ $ Str = "rmdir/s/q". $ dir; } Else { $ Str = "rm-rf". $ dir; } } |
File deletion code 3
The code is as follows: |
Copy code |
$ Info = "a123"; // directory name If (is_dir ($ info )){ If (rmdir ($ info )){ Echo "the directory {$ inof} has been deleted: www.111cn.net "; } Else { Echo "directory cannot be deleted! Cause: A file still exists in the directory! "; } } If (is_file ($ info )){ If (unlink ($ info )){ Echo "file {$ info} deleted ...! "; } Else { Echo "file {$ info} mb.111cn.net deletion failed ...! Try to modify the file permission to delete ..."; If (chmod ($ info, 0777 )){ Unlink ($ info ); Echo "file {$ info} permission modified and deleted ..."; } Else { Echo "the file {$ info} cannot be deleted on the web. The ftp permission may be set for this file ..."; } } } |
Recently, many websites have been reposted on this site. Please add this site connection. Thank you for your cooperation!