Delete php code for all files in the specified folder

WBOY
Release: 2016-07-25 09:00:31
Original
887 people have browsed it
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;
}
}
}
?>
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template