89 lines
2.1 KiB
PHP
89 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
set_time_limit(0);
|
||
|
|
|
||
|
|
ini_set('display_errors', 1);
|
||
|
|
error_reporting(E_ALL);
|
||
|
|
|
||
|
|
$dirPath = $_SERVER['DOCUMENT_ROOT']."/upload/reqs";
|
||
|
|
|
||
|
|
$sum = 0;
|
||
|
|
|
||
|
|
for($num = 0; $num <= 3000000; $num++) {
|
||
|
|
|
||
|
|
$tempDir = $dirPath . "/" . $num;
|
||
|
|
|
||
|
|
if (is_dir($tempDir)) {
|
||
|
|
clearReqDir($tempDir, $sum);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
echo "<br/>".formatSizeUnits($sum);
|
||
|
|
|
||
|
|
function clearReqDir($dirPath, &$sum) {
|
||
|
|
|
||
|
|
if (!is_dir($dirPath)) {
|
||
|
|
throw new InvalidArgumentException("$dirPath must be a directory");
|
||
|
|
}
|
||
|
|
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
|
||
|
|
$dirPath .= '/';
|
||
|
|
}
|
||
|
|
$files = glob($dirPath . '*', GLOB_MARK);
|
||
|
|
|
||
|
|
foreach ($files as $file) {
|
||
|
|
if (is_dir($file)) {
|
||
|
|
clearReqDir($file, $sum);
|
||
|
|
} else {
|
||
|
|
$url = str_replace("/var/www/sites/joywork.ru/prod", "https://uf.joywork.ru", $file);
|
||
|
|
|
||
|
|
echo "check url " . $url . "<br/>";
|
||
|
|
|
||
|
|
$res = doesFileUrlExists($url);
|
||
|
|
|
||
|
|
if ($res[0]) {
|
||
|
|
|
||
|
|
$size = filesize($file);
|
||
|
|
$sum = $sum + $size;
|
||
|
|
|
||
|
|
echo "delete " . $file . " " . date("d.m.Y H:i:s.", filemtime($file)) . " size: " . formatSizeUnits($size) . "<br/>";
|
||
|
|
//если файл есть в селектел, удаляем локальный файл
|
||
|
|
unlink($file);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function doesFileUrlExists($url) {
|
||
|
|
$headers = get_headers($url, true);
|
||
|
|
return [(stripos($headers[0], "200 OK") ? true : false), (isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0)];
|
||
|
|
}
|
||
|
|
|
||
|
|
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;
|
||
|
|
}
|