Update: 2026-06-12 01:23:54
This commit is contained in:
@@ -172,6 +172,42 @@ function appLog(string $message, string $level = 'INFO'): void
|
||||
@error_log($entry . PHP_EOL, 3, $logDir . '/app.log');
|
||||
}
|
||||
|
||||
function uploadLog(string $message, string $level = 'INFO', array $context = []): void
|
||||
{
|
||||
$logDir = __DIR__ . '/../logs';
|
||||
if (!is_dir($logDir)) {
|
||||
@mkdir($logDir, 0777, true);
|
||||
}
|
||||
|
||||
if (!isset($context['ip'])) {
|
||||
$context['ip'] = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
|
||||
}
|
||||
if (!isset($context['user_agent'])) {
|
||||
$context['user_agent'] = $_SERVER['HTTP_USER_AGENT'] ?? 'unknown';
|
||||
}
|
||||
|
||||
if (isset($context['upload_error_code'])) {
|
||||
$errCode = $context['upload_error_code'];
|
||||
$context['upload_error_desc'] = match ($errCode) {
|
||||
UPLOAD_ERR_OK => 'UPLOAD_ERR_OK (0): No error, file uploaded successfully.',
|
||||
UPLOAD_ERR_INI_SIZE => 'UPLOAD_ERR_INI_SIZE (1): The uploaded file exceeds the upload_max_filesize directive in php.ini.',
|
||||
UPLOAD_ERR_FORM_SIZE => 'UPLOAD_ERR_FORM_SIZE (2): The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
|
||||
UPLOAD_ERR_PARTIAL => 'UPLOAD_ERR_PARTIAL (3): The uploaded file was only partially uploaded (common on weak/3G networks).',
|
||||
UPLOAD_ERR_NO_FILE => 'UPLOAD_ERR_NO_FILE (4): No file was uploaded.',
|
||||
UPLOAD_ERR_NO_TMP_DIR => 'UPLOAD_ERR_NO_TMP_DIR (6): Missing a temporary folder.',
|
||||
UPLOAD_ERR_CANT_WRITE => 'UPLOAD_ERR_CANT_WRITE (7): Failed to write file to disk.',
|
||||
UPLOAD_ERR_EXTENSION => 'UPLOAD_ERR_EXTENSION (8): A PHP extension stopped the file upload.',
|
||||
default => "Unknown upload error code: $errCode",
|
||||
};
|
||||
}
|
||||
|
||||
$entry = date('Y-m-d H:i:s') . " [$level] " . $message;
|
||||
if ($context) {
|
||||
$entry .= ' | ' . json_encode($context, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
@error_log($entry . PHP_EOL, 3, $logDir . '/upload.log');
|
||||
}
|
||||
|
||||
function debugLog(string $message): void
|
||||
{
|
||||
appLog($message, 'DEBUG');
|
||||
|
||||
Reference in New Issue
Block a user