Сам скрипт:
CODE (htmlphp):
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?
- if (!defined('DATALIFEENGINE')) {
- define('DATALIFEENGINE', true);
- }
- #позвол¤ем скрипту анализировать картинки без лимита (если их много будет)
- set_time_limit(0);
- # ----------------------- декларирование основных параметров ------------------------
- #путь к папке с картинками
- define("IMGDIR", 'uploads/posts/2017-01/thumbs');
- #путь к конфигу
- define("CONF", 'engine/data/dbconfig.php');
- define( 'DATALIFEENGINE', true );
- #задать произвольный логин и пороль админа
- define( 'LOGIN', 'ushkom' );
- define( 'PASSWORD', 'ushkom102030' );
- class db{}
- # ----------------------- проверки ------------------------
- if (!is_dir(IMGDIR))
- die(IMGDIR . ' not found!');
- #подключаем длешный конфиг
- if (!file_exists(CONF))
- die(CONF .' not found!');
- include CONF ;
- # ----------------------- настройки ------------------------
- header("Content-Type: text/html; charset=".COLLATE);
- # ----------------------- класы и функции ------------------------
- class SQL
- {
- public $server,$user,$password,$database,$connected;
- function __construct($server,$password,$database,$user)
- {
- $this -> count = 0;
- $this -> connected = false;
- $this -> server = $server;
- $this -> user = $user;
- $this -> password = $password;
- $this -> database = $database;
- }
- function SetBase($base)
- {
- $this->database = trim($base);
- }
- function connect()
- {
- if ($this->connected)
- mysql_close();
- $curent = @mysql_connect ($this->server, $this->user, $this->password);
- if (!$curent)
- {
- $this->connected = false;
- return( mysql_error() );
- }
- unset($curent);
- $curent = @mysql_select_db ($this->database);
- if (!$curent)
- {
- $this->connected = false;
- return( mysql_error() );
- }
- $this->connected = true;
- $this->run("SET NAMES ".COLLATE);
- return $this->connected;
- }
- function query($query)
- {
- $result = $this->run($query);
- if (!$result)
- return(mysql_error());
- $d = array ();
- while ($row = mysql_fetch_assoc($result))
- $d[] = $row;
- return $d;
- }
- function run($query)
- {
- if (!$this->connected)
- $this -> connect();
- $query = trim($query);
- $result = mysql_query($query);
- return $result;
- }
- function SimpleQuery($query)
- {
- $result = $this->run($query);
- if (!$result)
- return(mysql_error());
- $d = array ();
- while ($row = mysql_fetch_assoc($result))
- return $row;
- return false;
- }
- }
- function IsUsed($name)
- {
- global $sql;
- $name = addslashes($name);
- $data = $sql -> query("select `id` from `" . PREFIX ."_post` where `short_story` like '%$name%' or `full_story` like '%$name%' or `xfields` like '%$name%'");
- if (!$data) return false;
- if (!isset($data[0])) return false;
- $id = '';
- foreach ($data as $c)
- {
- $id .= '<b>' . $c['id'] . '</b> , ';
- }
- return rtrim($id , ', ');
- }
- #--------------------авторизаци¤--------------------------------
- if (isset($_POST['Tlogin']))
- {
- if ($_POST['login'] == LOGIN && $_POST['password'] == PASSWORD) $_SESSION['logined'] = true;
- }
- if (!isset($_SESSION['logined']))
- {
- #если не залогинен
- ?>
- <form method="POST">
- LOGIN:</br><input type="text" name="login"></br>
- PASSWORD:</br><input type="password" name="password"></br>
- <input type="submit" name="Tlogin">
- </form>
- <?
- exit(0);
- }
- #всЄ ниже если залогинен
- #--------------------попытка подключитс¤ к базе----------------
- $sql = new SQL( DBHOST , DBPASS , DBNAME , DBUSER );
- $error = $sql -> connect();
- if (!$sql -> connected) die($error);
- #--------------главна¤ часть-------------
- $images = array_merge( glob(IMGDIR .'/*.jpg') , glob(IMGDIR .'/*.jpeg') , glob(IMGDIR .'/*.gif') , glob(IMGDIR .'/*.png'));
- ?>
- <table border="4">
- </tr>
- <th>
- название
- </th>
- <th>
- используетс¤ (id)
- </th>
- <th>
- предосмотр
- </th>
- <th>
- ”далить
- </th>
- </tr>
- <? foreach($images as $img)
- {
- echo "<tr>";
- #name
- echo "<td><a href='$img' target='blank'>$img</a></td>";
- #used
- $ids = IsUsed($img);
- if (!$ids)
- echo "<td><font color='red'>нигде не используется !</font></td>";
- else
- echo "<td>$ids</td>";
- echo "<td><img src='$img' height='50px'></img></td><td><a href='?d=".$img."'>Удалить!!!</a><br></td>";
- if (!empty($_GET['d'])){
- unlink($_GET['d']);}
- }
- ?>
- </table>