Home >Backend Development >PHP Tutorial >Delete php code for all files in the specified folder
Delete all files in the specified folder. The code is very simple and suitable for beginners.
Full code. <?php /** * 删除文件夹中所有文件 * by http://bbs.it-home.org */ $cacheDir = '../cache/myfiles'; $dh = opendir($cacheDir); while ( $file = readdir($dh) ) { if (($file == '.') || ($file == '..')) { continue; } if (file_exists( $cacheDir . '/' .$file)) { if (!unlink($cacheDir . '/' . $file)) { break; } } } ?> |