Code tối ưu ngắn gọn xóa tất cả các tập tin trong thư mục, xóa thư mục.
1. Code tối ưu ngắn gọn xóa tất cả các tập tin trong thư mục
array_map('unlink', glob("$dirname/*.*"));
Khi thư mục đã rỗng, xóa thư mụcrmdir($dirname);
2. Sao chép Copy thư mục với PHP
<?php
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
$src = '/path/of/source/';
$dst = '/path/to/destination/';
recurse_copy($src,$dst);
?>
https://drive.google.com/file/d/0B2dyM8C-Tt-jUU1wVHRZdXFRXzA/view?usp=sharing
Trả lờiXóa