Last active
April 18, 2018 22:05
-
-
Save mitrallex/78c2a30c2195316bec497c79bd918c97 to your computer and use it in GitHub Desktop.
CLeanFTP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <style type="text/css">@import url("style.css");</style> | |
| <style type="text/css">@import url("bulma.min.css");</style> | |
| <?php | |
| // Define main variables | |
| $im_folders = array('images', 'images10', 'images35', 'images_t', 'images_hq'); | |
| /** | |
| * Select server | |
| * @return array Server params | |
| */ | |
| /** | |
| * Ger server information | |
| * @param integer $server_to_choose User choice | |
| * @return array Server params | |
| */ | |
| function getServerInfo($server_to_choose) { | |
| $server = array(); | |
| switch ($server_to_choose) { | |
| case 1: | |
| $server = array('name'=>'name', | |
| 'ip'=>'255.255.255.255', | |
| 'login'=>'login', | |
| 'password'=>'password', | |
| 'root_dir'=>'root_dir/' | |
| ); | |
| break; | |
| case 2: | |
| $server = array('name'=>'name', | |
| 'ip'=>'255.255.255.255', | |
| 'login'=>'login', | |
| 'password'=>'password', | |
| 'root_dir'=>'root_dir/' | |
| ); | |
| break; | |
| case 3: | |
| $server = array('name'=>'name', | |
| 'ip'=>'255.255.255.255', | |
| 'login'=>'login', | |
| 'password'=>'password', | |
| 'root_dir'=>'root_dir/' | |
| ); | |
| break; | |
| default: | |
| $server = array('name'=>'name', | |
| 'ip'=>'255.255.255.255', | |
| 'login'=>'login', | |
| 'password'=>'password', | |
| 'root_dir'=>'root_dir/' | |
| ); | |
| break; | |
| } | |
| return $server; | |
| } | |
| if ($_POST) { | |
| $filename = isset($_POST['filename']) ? $_POST['filename'] : ''; | |
| $server = isset($_POST['server']) ? $_POST['server'] : ''; | |
| $subfolder = isset($_POST['subfolder']) ? $_POST['subfolder'] : ''; | |
| $is_root = (isset($_POST['is_root']) && $_POST['is_root'] == 'on') ? true : false; | |
| $errors = array(); | |
| $answer = array(); | |
| if (empty($filename) || empty($server)) { | |
| if (empty($filename)) { | |
| $errors['filename'] = 'Имя файла не может быть пустым!'; | |
| } | |
| if (empty($server)) { | |
| $errors['server'] = 'Сервер не выбран!'; | |
| } | |
| } elseif (strpos($filename, '_') == false && !$is_root) { | |
| $errors['filename'] = 'Некорректное имя файла! Введите корректное имя либо воспользуйтесь полями в блоке "Дополнительные параметры" (нажмите "Справка" для уточнения деталей)'; | |
| } else { | |
| $server_info = getServerInfo($server); | |
| $answer[] = "<strong>{$server_info['name']}</strong>:"; | |
| // Connect to the server and log in | |
| $connect_id = ftp_connect($server_info['ip']) or die("Could not connect to {$server_info['name']}"); | |
| ftp_login($connect_id, $server_info['login'], $server_info['password']); | |
| foreach ($im_folders as $im_folder) { | |
| if ($is_root) { | |
| $file = $server_info['root_dir'] . $im_folder . '/' .$filename; | |
| } elseif (!empty($subfolder)) { | |
| $file = $server_info['root_dir'] . $im_folder . '/' . $subfolder . '/' .$filename; | |
| } else { | |
| if (strpos($filename, '_') != false) { | |
| $subfolder = explode('_', $filename); | |
| $subfolder = $subfolder[0]; | |
| $file = $server_info['root_dir'] . $im_folder . '/' . $subfolder . '/' .$filename; | |
| } | |
| } | |
| $file_exist = ftp_size($connect_id, $file); | |
| if ($file_exist != -1) { | |
| if (ftp_delete($connect_id, $file)) { | |
| $answer[] = "Файл <strong>{$file}</strong> успешно удален из {$im_folder}!"; | |
| } else { | |
| $answer[] = "Не удалось удалить файл <strong>{$file}</strong>"; | |
| } | |
| } else { | |
| $answer[] = "Файл <strong>{$file}</strong> отсутствует в папке <strong>{$im_folder}</strong>!"; | |
| } | |
| } | |
| // Close connection | |
| ftp_close($connect_id); | |
| } | |
| } | |
| ?> | |
| <div class="container"> | |
| <div class="notification is-info <?php echo (isset($answer) && !empty($answer)) ? 'show' : ''; ?>"> | |
| <button class="delete" id="close-notification"></button> | |
| <?php if (isset($answer) && !empty($answer)): ?> | |
| <?php foreach ($answer as $server_answer): ?> | |
| <?php echo $server_answer . '<br>'; ?> | |
| <?php endforeach; ?> | |
| <?php endif; ?> | |
| </div> | |
| <form action="/" method="post"> | |
| <div class="field"> | |
| <label class="label">Имя файла*</label> | |
| <div class="control"> | |
| <input class="input <?php echo (isset($errors['filename'])) ? 'is-danger' : ''; ?>" type="text" name="filename" value="<?php if (!empty($filename)) echo $filename; ?>" placeholder="Имя файла"> | |
| </div> | |
| <?php if (isset($errors['filename'])): ?> | |
| <p class="help is-danger"> <?php echo $errors['filename']; ?></p> | |
| <?php endif; ?> | |
| </div> | |
| <div class="field"> | |
| <label class="label">Сервер*</label> | |
| <div class="control"> | |
| <div class="select <?php echo (isset($errors['server'])) ? 'is-danger' : ''; ?>"> | |
| <select name="server"> | |
| <option value="0">Выберите сервер из списка ниже</option> | |
| <option value="1">Сервер 1</option> | |
| <option value="2">Сервер 2</option> | |
| <option value="3">Сервер 3</option> | |
| </select> | |
| </div> | |
| </div> | |
| <?php if (isset($errors['server'])): ?> | |
| <p class="help is-danger"><?php echo $errors['server']; ?></p> | |
| <?php endif; ?> | |
| </div> | |
| <div class="field"> | |
| <a href="#" id="addition-button">Дополнительные параметры</a> | |
| </div> | |
| <div id="addition-block"> | |
| <div class="field"> | |
| <label class="label">Наименование директории</label> | |
| <div class="control"> | |
| <input class="input" type="text" name="subfolder" placeholder="Наименование директории"> | |
| </div> | |
| </div> | |
| <div class="field"> | |
| <label class="checkbox"> | |
| <input type="checkbox" name="is_root"> | |
| Удалить из корневой папки | |
| </label> | |
| </div> | |
| </div> | |
| <div class="field"> | |
| <div class="control"> | |
| <button type="submit" class="button is-link is-outlined is-pulled-right" id="send">Удалить файл</button> | |
| <button type="submit" class="button is-link is-outlined is-pulled-left" id="about">Справка</button> | |
| </div> | |
| </div> | |
| </form> | |
| </div> | |
| <!-- App description in modal window --> | |
| <div class="modal"> | |
| <div class="modal-background"></div> | |
| <div class="modal-card"> | |
| <header class="modal-card-head"> | |
| <p class="modal-card-title">CLeanFTP</p> | |
| <button class="delete" aria-label="close" id="modal-close"></button> | |
| </header> | |
| <section class="modal-card-body"> | |
| <div class="content"> | |
| <p> | |
| Это приложение поможет вам удалить определенное изображение по FTP протоколу. | |
| </p> | |
| <p> | |
| <span style="font-style: italic;">Обязательные параметры</span>:<br> | |
| <ol> | |
| <li> | |
| Имя файла (обязательно должно начинаться с xxx, пример "aaa_2017_..."). | |
| </li> | |
| <li> | |
| Сервер, с которого будет происходить удаление. | |
| </li> | |
| </ol> | |
| </p> | |
| <p> | |
| <span style="font-style: italic;">Дополнительные параметры</span>:<br> | |
| <ol> | |
| <li> | |
| Наименование директории (определить директорию xxxxxx самостоятельно, пример "aaa"). | |
| </li> | |
| <li> | |
| Удалить из корневой папки (позволяет удалять изображение из корневой директории - | |
| images, images35, images10, images_t, images_hq). | |
| </li> | |
| </ol> | |
| </p> | |
| </div> | |
| </section> | |
| </div> | |
| </div> | |
| <script> | |
| window.onload = function() { | |
| var addition_button = document.getElementById('addition-button'); | |
| addition_button.addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| var addition_block = document.getElementById('addition-block'); | |
| addition_block.classList.toggle('show'); | |
| }); | |
| document.getElementById('close-notification').addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| document.querySelector('.notification').classList.remove('show'); | |
| }); | |
| document.getElementById('about').addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| document.querySelector('.modal').classList.add('is-active'); | |
| }); | |
| document.getElementById('modal-close').addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| document.querySelector('.modal').classList.remove('is-active'); | |
| }); | |
| document.querySelector('.modal-background').addEventListener('click', function(e) { | |
| e.preventDefault(); | |
| document.querySelector('.modal').classList.remove('is-active'); | |
| }); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment