Files
minicrm/check-upload.php
phuongtc 96e1ce4f40
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled
hoàn thiện upload và global search
2026-05-06 04:10:14 +00:00

61 lines
1.8 KiB
PHP

<?php
/**
* Check PHP upload limits
* Run: php check-upload.php
*/
echo "=== PHP Upload Limits ===" . PHP_EOL;
echo "upload_max_filesize: " . ini_get('upload_max_filesize') . PHP_EOL;
echo "post_max_size: " . ini_get('post_max_size') . PHP_EOL;
echo "memory_limit: " . ini_get('memory_limit') . PHP_EOL;
echo "max_execution_time: " . ini_get('max_execution_time') . PHP_EOL;
echo PHP_EOL;
// Check if limits are sufficient
$uploadMax = parseSize(ini_get('upload_max_filesize'));
$postMax = parseSize(ini_get('post_max_size'));
echo "=== Status ===" . PHP_EOL;
echo "Max upload size: " . formatSize($uploadMax) . PHP_EOL;
echo "Max post size: " . formatSize($postMax) . PHP_EOL;
if ($uploadMax < 50 * 1024 * 1024) {
echo PHP_EOL . "WARNING: upload_max_filesize is too small!" . PHP_EOL;
echo "Current: " . ini_get('upload_max_filesize') . PHP_EOL;
echo "Required: 50M or higher" . PHP_EOL;
echo PHP_EOL . "Solutions:" . PHP_EOL;
echo "1. Edit /etc/php/8.3/cli/php.ini" . PHP_EOL;
echo "2. Run: php -d upload_max_filesize=50M artisan serve" . PHP_EOL;
echo "3. Use: ./start-server.sh" . PHP_EOL;
} else {
echo PHP_EOL . "OK: Upload limits are sufficient!" . PHP_EOL;
}
function parseSize(string $size): int
{
$unit = strtolower(substr($size, -1));
$value = (int) $size;
return match ($unit) {
'g' => $value * 1024 * 1024 * 1024,
'm' => $value * 1024 * 1024,
'k' => $value * 1024,
default => $value,
};
}
function formatSize(int $bytes): string
{
if ($bytes >= 1024 * 1024 * 1024) {
return round($bytes / (1024 * 1024 * 1024), 2) . ' GB';
}
if ($bytes >= 1024 * 1024) {
return round($bytes / (1024 * 1024), 2) . ' MB';
}
if ($bytes >= 1024) {
return round($bytes / 1024, 2) . ' KB';
}
return $bytes . ' bytes';
}