Добрый день. Нужен скрипт для сравнения ссылок на изображения в базе и соответственно в папке на сервере. Если ссылки в базе нет а в папке есть это изображение, его с сервера удаляем. в сети нашел несколько похожих скриптов и собрал их в один. Сам скрипт: Код (Text): <? 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); session_start(); # ----------------------- класы и функции ------------------------ 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')); if (is_null($images) || !isset($images['0'])) die("нет картинок !"); ?> <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> Подскажите как можно сделать выборку и выводить только картинки которые не используются, и как их после просмотра можно массово удалить? большое всем спасибо за помощь.
Всем спасибо, сам нашел способ. Может кому пригодится Код (Text): <script src="http://code.jquery.com/jquery-1.8.3.js"></script> <? if (!defined('DATALIFEENGINE')) { define('DATALIFEENGINE', true); } #позвол¤ем скрипту анализировать картинки без лимита (если их много будет) set_time_limit(0); # ----------------------- декларирование основных параметров ------------------------ #путь к папке с картинками define("IMGDIR", 'uploads/posts/2017-01'); #путь к конфигу 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); session_start(); # ----------------------- класы и функции ------------------------ 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')); if (is_null($images) || !isset($images['0'])) die("нет картинок !"); ?> <script language="javascript" type="text/javascript"> $(document).ready(function() { $("#check_all").click(function () { if (!$("#check_all").is(":checked")) $(".checkbox").removeAttr("checked"); else $(".checkbox").attr("checked","checked"); }); }); </script> <form method="get" action=""> <table border="4"> <tr> <th> название </th> <th> используетс¤ (id) </th> <th> предосмотр </th> <th> ”далить </th> </tr> <? foreach($images as $img) { $ids = IsUsed($img); if (!$ids || $img){ $img1 = $img; } echo "<tr>"; #name if (!$ids) echo "<td><a href='$img1' target='blank'>$img1</a></td>"; #used if (!$ids) echo "<td><font color='red'>нигде не используетс¤ !</font></td>"; if (!$ids) echo "<td><img src='$img1' height='50px'></img><br></td>"; if (!$ids) echo "<td><label><input class=checkbox type=checkbox name=delfile[] value=$img1></label><br></td>"; echo "</tr>"; } ?> </table> <br> <label><input type="checkbox" id="check_all"> Выделить всё</label><br> <br> <input type="submit" name="sub" value="Удалить все!!!" /><br> </form> <? if (!empty($_GET[delfile])) { foreach ($_GET[delfile] as $filename) { unlink("".$filename); } } ?>