0 and object_id not in (select id from objects)";
$rezObj = mysql_query($sqlObj);
while ($obj = mysql_fetch_assoc($rezObj)) {
echo " Удаляем объект ".$obj['object_id'] . "
";
$path = $_SERVER['DOCUMENT_ROOT']."/upload/objects/" . $obj['object_id'] . "/";
$files = glob($path . '*', GLOB_MARK);
if (count($files) == 0) {
echo "Нет файлов";
} else {
foreach ($files as $file) {
$size = filesize($file);
$sum = $sum + $size;
echo $file . " " . date("d.m.Y H:i:s.", filemtime($file)) . " size: " . formatSizeUnits($size) . "
";
//unlink($file);
$count++;
}
}
//удалить запись из таблицы
//$sqlDelete = "DELETE FROM clients_files where object_id > 0 and object_id = " . $obj['object_id'];
//mysql_query($sqlDelete);
$countAll++;
}
echo "Удалено " . $countAll . " записей
";
echo "Удалено " . $count . " файлов
";
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;
}
?>