Joywork/cron/copyNewbuildingsImages.php
2026-05-22 21:21:54 +03:00

53 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
set_time_limit(0);
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
$dirPath = $_SERVER['DOCUMENT_ROOT'] . "/abc/";
// разность в часах для копирования
$deltaMin = 6;
$numCopy = 0;
$numErr = 0;
$now = time();
echo "Начинаем копирование<br/> $deltaMin <br/>";
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 (stripos(basename($file), ".xml") === false) {
// картинки за последние $deltaMin часов
if ($now - filemtime($file) < 60 * 60 * $deltaMin) {
echo $file . " - ";
$fn = pathinfo($file, PATHINFO_FILENAME);
$fnWithExt = pathinfo($file, PATHINFO_BASENAME);
$dir = substr($fn, -2, 2);
ftp_mkdir($conn, "/photos/newbuildings/$dir");
$dstFile = "/photos/newbuildings/$dir/$fnWithExt";
if (ftp_put($conn, $dstFile, $file, FTP_ASCII)) {
echo "скопирован в $dstFile";
$numCopy++;
} else {
echo "не скопирован в $dstFile";
$numErr++;
}
echo "<br>";
}
}
}
echo "Скопировано " . $numCopy . ", ошибка при копировании " . $numErr;