".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 . "
"; $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) . "
"; //если файл есть в селектел, удаляем локальный файл 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; }