Cafemmo Club
← Quay lại danh sách

Giờ các bác help

laogiavn08/06/2021947 lượt xem7 bình luận
E mới học code đang gặp khó khăn với đoạn này. E muốn viết bằng PHP chuyển các file từ các subfolder ra root folder theo dạng như sau:
root/1/a.html
root/1/b.html
root/2/c.html
root/3/d.html
root/a.html
root/b.html
root/c.html
root/d.html
Mình có sử dụng code này nhưng ý mình muốn khi chạy hàm này nó sẽ auto move tất cả các file trong subfolder (các subfolder này thay đổi tên liên tục không cố định) ra root sau đó remove all subfolder đó ra mà mãi ko đc.
// Get array of all source files
$files = scandir("source");
// Identify directories
$source = "source/";
$destination = "destination/";
// Cycle through all source files
foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
// If we copied this successfully, mark it for deletion
if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
// Delete all successfully-copied files
foreach ($delete as $file) {
unlink($file);
}

Bình luận

Đang tải...

Đang kiểm tra đăng nhập...

Giờ các bác help · Cafemmo Club