|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +require_once __DIR__.'/functions.php'; |
3 | 4 |
|
4 | 5 | /**
|
5 | 6 | * delete media
|
|
103 | 104 |
|
104 | 105 | // change directory
|
105 | 106 | if(isset($_POST['selected_folder'])) {
|
| 107 | + echo 'Swapped folder'; |
106 | 108 | $_SESSION['disk'] = se_filter_filepath($_POST['selected_folder']);
|
107 | 109 | header( "HX-Trigger: update_uploads_list");
|
108 | 110 | }
|
109 | 111 |
|
110 |
| -/** |
111 |
| - * create new folder |
112 |
| - */ |
| 112 | +// create new folder |
113 | 113 | if((isset($_POST['new_folder'])) && ($_POST['new_folder'] != '')) {
|
114 | 114 | $folder_name = clean_filename($_POST['new_folder']);
|
115 | 115 | $create_path = $_SESSION['disk'] . '/' . $folder_name;
|
116 | 116 | mkdir($create_path, 0777, true);
|
117 | 117 | header( "HX-Trigger: update_directories");
|
118 | 118 | }
|
119 | 119 |
|
| 120 | +// delete folder |
| 121 | +if(isset($_POST['delete_dir'])) { |
| 122 | + $del_dir = se_filter_filepath($_POST['delete_dir']); |
| 123 | + delete_folder($del_dir); |
| 124 | + header( "HX-Trigger: update_directories, update_uploads_list"); |
| 125 | +} |
| 126 | + |
| 127 | + |
120 | 128 | /**
|
121 | 129 | * rebase the database
|
122 | 130 | * we check if there are files which are not in the database
|
|
138 | 146 | $scan_files = se_scandir_recursive("$files_dir");
|
139 | 147 | $images_and_files = array_merge($scan_images, $scan_files);
|
140 | 148 |
|
| 149 | + $cnt_images_on_disk = 0; |
| 150 | + if(is_array($scan_images)) { |
| 151 | + $cnt_images_on_disk = count($scan_images); |
| 152 | + } |
| 153 | + |
| 154 | + $cnt_files_on_disk = 0; |
| 155 | + if(is_array($scan_files)) { |
| 156 | + $cnt_files_on_disk = count($scan_files); |
| 157 | + } |
| 158 | + |
141 | 159 | foreach ($images_and_files as $key => $value) {
|
142 | 160 | if(str_contains("$value","index.html")) { continue; }
|
143 | 161 | $all_files[] = str_replace('assets/', '../', $value);
|
|
150 | 168 |
|
151 | 169 | foreach($all_files as $filename) {
|
152 | 170 | if(!in_array($filename, $mediaData)) {
|
153 |
| - // filename is not in database, mak an entry |
154 |
| - |
| 171 | + // filename is not in database, make an entry |
155 | 172 | $file_src = str_replace("../","assets/",$filename);
|
156 | 173 | $filesize = filesize($file_src);
|
157 | 174 | $filemtime = filemtime($file_src);
|
|
183 | 200 | }
|
184 | 201 | }
|
185 | 202 |
|
186 |
| - |
| 203 | + echo '<p>Found <code>'.$cnt_images_on_disk.'</code> images and <code>'.$cnt_files_on_disk.'</code> files.</p>'; |
187 | 204 | echo '<p><code>'.$stats_files_to_db.'</code> were added to the database<br>';
|
188 | 205 | echo '<code>'.$stats_files_from_db.'</code> were removed from the database</p>';
|
| 206 | + header( "HX-Trigger: update_uploads_list"); |
189 | 207 |
|
190 | 208 | }
|
191 | 209 |
|
|
0 commit comments