How to copy or delete a directory in PHP

xiaoxiao2021-03-06  18

How to copy or delete a directory PHP in PHP is used to copy files, no corresponding copying directory, in fact, this is also very simple, mainly using MKDIR () and Copy () combined with future return For deletion, it is also use RMDIR () and unlink () to deliver Copy Directory: Function CopyDir ($ Source, $ Destination) {$ Result = true; if (! Is_dir ($ source)) {Trigger_ERROR ('Invalid Parameter', E_USER_ERROR);} f (! Is_dir ($ destination)) {if (! MKDIR ($ Destination, 0700)) {Trigger_ERROR ('Invalid Parameter', E_USER_ERROR);}} $ hand = OpenDir ($ Source); While ($ file = readdir)! == false) {if ($ file! = '.' && $ file! = '..') {$ src = $ source. Directory_separator. $ $ DTN = $ DESTINATION. DIRECTORY_SEPArator. $ file; if (is_dir ($ src)) {CopyDir ($ SRC, $ DTN);} else {if (! Copy ($ src, $ dtn)) {$ Result = False; Break;}}}} closedir ($ hand); RETU Rn $ Result;}?> Delete Directory code: Note:

转载请注明原文地址:https://www.9cbs.com/read-48509.html

New Post(0)