View file up/mysql.php

File size: 4.06Kb
<?php
require_once"../template/start.php";
require_once"../template/regglobals.php";
require_once"../template/config.php";
require_once"../template/functions.php";
require_once"../template/antidos.php";
require_once"../template/cookies.php";
require_once"../template/gzip.php";
require_once"../template/header.php";
require_once"../template/referer.php";
include_once"../themes/$config_themes/index.php";
include_once"../template/isset.php";

require_once "moduls/config.php";
require_once "moduls/functions.php";
require_once "moduls/connect.php";

$action = $_GET['action'];
$id = abs((int)$_GET['id']);

if ($dostup==101){
echo '<img src="../images/img/partners.gif" alt=""> <b>Работа с базой</b><br><br>';

// работа с базой

set_time_limit(0);
$addfolder = 0;
$addfiles = 0;

$reses = mysql_query("SELECT `path` FROM `".$preff."_files` ");
$file_info = array();
while($fn = mysql_fetch_row($reses)) $file_info[] = $fn[0];

if($action=="obnov"){
$data = mysql_fetch_row(mysql_query("SELECT `path` FROM `".$preff."_files` WHERE `id` = '".$id."'"));
$path = $data[0];
if($path=="") $path = $downpath;

$fn = array();
$fn = dir_scan($path);
if($fn=="") $fn[] = $path;

foreach ($fn as $value){
$fold = dirname($value);

$data = mysql_fetch_array(mysql_query("SELECT `oform` FROM `".$preff."_files` WHERE `path` = '".$value."'"));

$oform=explode(":", $data['oform']);

if(!in_array($value,$file_info)){
$di = strrpos($value,"/");
$di = substr($value,$di+1,999);
$query = mysql_query("INSERT INTO `".$preff."_files` (`path`, `fname`, `infolder`) VALUES ('$value', '$di', '$fold');");
$addfolder++;
}

$odir = opendir($value);

while($fid = readdir($odir)){
$ex = format($fid);

if($fid!="." && $fid != ".." && in_array($ex,$oform) && !in_array("$value/$fid", $file_info)){

$ex = pathinfo("$value/$fid");

$ex = $ex['extension'];

$upltime = filectime("$value/$fid");

if($ex!="txt"){
if(is_file("$value/$fid.txt")) $about=file_get_contents("$value/$fid.txt"); else $about="";
} else $about = file_get_contents("$value/$fid");

$size = filesize("$value/$fid");
$rr = str_replace(".".$ex,"",$fid);
$query = mysql_query("INSERT INTO `".$preff."_files` (`path`, `fname`, `infolder`, `size` , `timeupload`, `format`, `about`) VALUES ('$value/$fid', '$rr', '$value' , '$size' , '$upltime', '$ex', '$about');");
$addfiles++;
}
}
}
echo 'Добавлено папок: '.$addfolder.'<br>Добавлено файлов: '.$addfiles.'<br><br>';
}elseif($action=="clean"){
$delfiles = 0;
$reses = mysql_query("SELECT * FROM `".$preff."_files` ");
while($test = mysql_fetch_array($reses)){
$data = mysql_fetch_array(mysql_query("SELECT `oform` FROM `".$preff."_files` WHERE `path` = '".$test['infolder']."'"));
$oform = explode(":", $data['oform']);
if (!is_file("$test[infolder]/$test[fname].$test[format]") && !is_dir($test['path'])){
$res = mysql_query("DELETE FROM `".$preff."_files` WHERE `id` = '".$test['id']."'");
$query = mysql_query("SELECT * FROM `".$preff."_komm` WHERE `file` = '".$test['id']."' ORDER BY `time` DESC");
$array_id = array();
while($list_sw = mysql_fetch_array($query)){
$array_id[] = $list_sw['id'];
}
$total = sizeof($array_id);
for ($i = 0; $i < $total; $i++){
mysql_fetch_array(mysql_query("DELETE FROM `".$preff."_komm` WHERE `id` = ".$array_id[$i]));
}

$delfiles++;}}
echo 'Удалено '.$delfiles.' несуществующих объектов!<br><br>';
}elseif($action=="optim"){
mysql_query("OPTIMIZE TABLE `".$preff."_files`");
mysql_query("OPTIMIZE TABLE `".$preff."_komm`");
echo 'Базы данных оптимизированы!<br><br>';
}

} else {header ("Location: ../index.php?isset=404&".SID);}

echo '<img src="../images/img/back.gif" alt=""> <a href="index.php?id='.$id.'&amp;">Назад</a>';
echo '<br><img src="../images/img/reload.gif" alt=""> <a href="index.php?'.SID.'">К разделам</a><br>';
echo '<img src="../images/img/homepage.gif" alt=""> <a href="../index.php?'.SID.'">На главную</a><br>';
include_once"../themes/$config_themes/foot.php";
?>