1+ <?php
2+ error_reporting (1 );
3+ class Copy {
4+
5+ public $ name = 'this ' ;
6+
7+ function recursive_copy ($ src , $ dst ) {
8+ if (is_dir ($ src )) {
9+ $ dir = opendir ($ src );
10+
11+ mkdir ($ dst , 0777 , true );
12+
13+ while (( $ file = readdir ($ dir )) ) {
14+ if (( $ file != '. ' ) && ( $ file != '.. ' )) {
15+ if ( is_dir ($ src . '/ ' . $ file ) ) {
16+ $ this ->recursive_copy ($ src .'/ ' . $ file , $ dst .'/ ' . $ file );
17+ }
18+ else {
19+ copy ($ src .'/ ' . $ file , $ dst .'/ ' . $ file );
20+ }
21+ }
22+ }
23+ closedir ($ dir );
24+
25+ return ;
26+ } elseif (is_file ($ src )) {
27+ $ dir = substr ($ dst , 0 , strrpos ($ dst , '/ ' ));
28+ mkdir ($ dir , 0777 , true );
29+ copy ($ src , $ dst );
30+ }
31+ // print_r($src);die;
32+ }
33+ }
34+
35+ $ copy = new Copy ();
36+
37+ if (isset ($ _POST ['submit ' ]) && $ _POST ['submit ' ] == 'Submit ' ) {
38+ // print_r(getcwd());
39+ try {
40+ $ json = file_get_contents ($ _FILES ['file ' ]['tmp_name ' ]);
41+ } catch (Exception $ e ) {
42+ print_r ($ e ->getMessage ());
43+ die;
44+ }
45+
46+ $ json = json_decode ($ json , true );
47+
48+ $ fix_dst = (isset ($ json ['default_copy_path ' ]) ? $ json ['default_copy_path ' ] : getcwd ()) . '/ ' ;
49+
50+ require_once $ json ['default_path ' ] . '/admin/config.php ' ;
51+ require_once $ json ['default_path ' ] . '/config.php ' ;
52+
53+ // foreach ($json['all_files'] as $key => $folder) {
54+ // $copy->recursive_copy($json['default_path'] . '/' . $folder, $fix_dst . $folder);
55+ // }
56+ foreach ($ json ['single_file ' ] as $ key => $ file ) {
57+ // print_r($json['default_path'] . '/' . $file);
58+ $ copy ->recursive_copy ($ json ['default_path ' ] . '/ ' . $ file , $ fix_dst . $ file );
59+ }
60+ }
61+ ?>
62+
63+ <!DOCTYPE html>
64+ <html>
65+ <head>
66+ <title>CES Module Backup</title>
67+ </head>
68+ <body>
69+ <form action="" method="post" enctype="multipart/form-data">
70+ <label>Backup File Name</label> <input name="file_name" type="text" value="" placeholder="default name is backup1" />
71+ <br />
72+ <br />
73+ <label>Backup File</label> <input name="file" type="file" />
74+ <br />
75+ <br />
76+ <input type="submit" name="submit" value="Submit"/>
77+ </form>
78+ </body>
79+ </html>
0 commit comments