90 lines
2.0 KiB
PHP
90 lines
2.0 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
|
|
set_time_limit(0);
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
?>
|
|
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Очистка файлов объектов по запросу</title>
|
|
</head>
|
|
|
|
<body>
|
|
<?php
|
|
|
|
$countAll = 0;
|
|
|
|
$count = 0;
|
|
|
|
$sum = 0;
|
|
|
|
$sqlObj = "SELECT * FROM clients_files WHERE object_id > 0 and event_id > 0 and event_id not in (select ev.id from user_object_events ev) ORDER BY `id` DESC";
|
|
|
|
$rezObj = mysql_query($sqlObj);
|
|
|
|
while ($obj = mysql_fetch_assoc($rezObj)) {
|
|
|
|
echo " Удаляем файл ".$obj['name'] . " <br/>";
|
|
|
|
$file = $_SERVER['DOCUMENT_ROOT']."/upload/objects/" . $obj['object_id'] . "/" . $obj['guid'] . '.' . $obj['type'];
|
|
|
|
if (file_exists($file)) {
|
|
$size = filesize($file);
|
|
$sum = $sum + $size;
|
|
|
|
echo $file . " " . date("d.m.Y H:i:s.", filemtime($file)) . " size: " . formatSizeUnits($size) . "<br/>";
|
|
//unlink($file);
|
|
|
|
$count++;
|
|
}
|
|
|
|
|
|
//удалить запись из таблицы
|
|
//$sqlDelete = "DELETE FROM clients_files where object_id > 0 and object_id = " . $obj['object_id'];
|
|
//mysql_query($sqlDelete);
|
|
|
|
$countAll++;
|
|
}
|
|
|
|
|
|
echo "Удалено " . $countAll . " записей <br/>";
|
|
echo "Удалено " . $count . " файлов <br/>";
|
|
echo "Удалено " .formatSizeUnits($sum);
|
|
|
|
function formatSizeUnits($bytes)
|
|
{
|
|
if ($bytes >= 1073741824)
|
|
{
|
|
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
|
|
}
|
|
elseif ($bytes >= 1048576)
|
|
{
|
|
$bytes = number_format($bytes / 1048576, 2) . ' MB';
|
|
}
|
|
elseif ($bytes >= 1024)
|
|
{
|
|
$bytes = number_format($bytes / 1024, 2) . ' kB';
|
|
}
|
|
elseif ($bytes > 1)
|
|
{
|
|
$bytes = $bytes . ' bytes';
|
|
}
|
|
elseif ($bytes == 1)
|
|
{
|
|
$bytes = $bytes . ' byte';
|
|
}
|
|
else
|
|
{
|
|
$bytes = '0 bytes';
|
|
}
|
|
|
|
return $bytes;
|
|
}
|
|
|
|
?>
|
|
</body>
|
|
</html>
|