Home  >  Article  >  Backend Development  >  Delete php code for all files in the specified folder

Delete php code for all files in the specified folder

WBOY
WBOYOriginal
2016-07-25 09:00:31801browse
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;
}
}
}
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn