Php edition filters required files-PHP source code

Source: Internet
Author: User
Tags glob
Filter required files in php

1. [Code][PHP] code

 $ Value) {create_dir ($ root, $ value, $ target_time, $ target_dir) ;}} else {$ modify_time = filemtime ($ filename ); // add a file using filectime $ create_time = filectime ($ filename); if ($ modify_time >=$ target_time | $ create_time >=$ target_time) {$ root = preg_quote ($ root); $ str = file_get_contents ($ filename); $ filename = preg_replace ("@ $ root @", "", $ filename ); if (! Is_file ($ target_dir. $ filename) {file_put_contents ($ target_dir. $ filename, $ str);} echo $ filename ."
";}} Else {echo 'parameter error'; return false ;}// the second parameter controls whether to delete all or just delete the empty directory function remove_dir ($ target_dir, $ all_flg = false) {foreach (glob ("$ target_dir/*") as $ key => $ value) {if (is_dir ($ value) & count (glob ("$ value/*") = 0) {// delete the directory rmdir ($ value) for which the first-level directory is empty );} else if (is_dir ($ value) & count (glob ("$ value/*")> 0) {// verify all the subdirectories of the current directory. foreach (glob ("$ value/*") as $ sub_key => $ sub_value) {remove_dir ($ sub_value, $ all_flg );} // after processing in the previous step, return to the current directory and check whether the subdirectories of the current directory are empty. remove_dir ($ value, $ all_flg ); // if the current directory is empty after processing, delete if (is_dir ($ value) & count (glob ("$ value /*")) = 0) {rmdir ($ value) ;}} if ($ all_flg) {if (is_file ($ value) {unlink ($ value );}}}} // first clear the target directory remove_dir ($ target_dir, true); // re-create the directory create_dir ($ dir, $ dir, $ target_time, $ target_dir); sleep (1 ); // filter the remove_dir Directory ($ target_dir );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.