107 lines
3.1 KiB
PHP
107 lines
3.1 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
declare(strict_types=1);
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
* Diagnose für Bild-Uploads.
|
|||
|
|
*
|
|||
|
|
* php bin/check-upload.php
|
|||
|
|
* docker compose exec app php bin/check-upload.php
|
|||
|
|
*
|
|||
|
|
* Prüft GD, PHP-Limits und die Schreibrechte des Bildspeichers.
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
require dirname(__DIR__) . '/src/bootstrap.php';
|
|||
|
|
|
|||
|
|
$problems = 0;
|
|||
|
|
|
|||
|
|
function check(string $label, bool $ok, string $value): void
|
|||
|
|
{
|
|||
|
|
global $problems;
|
|||
|
|
|
|||
|
|
if (!$ok) {
|
|||
|
|
$problems++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
echo str_pad($label, 28) . ': ' . ($ok ? 'OK ' : 'FEHLER') . ' ' . $value . "\n";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
echo "Upload-Diagnose\n";
|
|||
|
|
echo str_repeat('=', 70) . "\n\n";
|
|||
|
|
|
|||
|
|
check('PHP-Version', PHP_VERSION_ID >= 80300, PHP_VERSION);
|
|||
|
|
|
|||
|
|
check('GD-Erweiterung', extension_loaded('gd'), extension_loaded('gd') ? 'geladen' : 'fehlt');
|
|||
|
|
|
|||
|
|
check('GD: Bilder lesen', function_exists('imagecreatefromstring'), function_exists('imagecreatefromstring') ? 'imagecreatefromstring() vorhanden' : 'fehlt');
|
|||
|
|
|
|||
|
|
$jpegOk = function_exists('imagejpeg')
|
|||
|
|
&& function_exists('imagetypes')
|
|||
|
|
&& (imagetypes() & IMG_JPG) === IMG_JPG;
|
|||
|
|
|
|||
|
|
check(
|
|||
|
|
'GD: JPEG schreiben',
|
|||
|
|
$jpegOk,
|
|||
|
|
$jpegOk ? 'imagejpeg() mit JPEG-Unterstützung vorhanden' : 'fehlt – GD wurde ohne libjpeg gebaut'
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
if (function_exists('imagetypes')) {
|
|||
|
|
$types = imagetypes();
|
|||
|
|
$formats = [];
|
|||
|
|
|
|||
|
|
foreach (['JPG' => IMG_JPG, 'PNG' => IMG_PNG, 'GIF' => IMG_GIF, 'WebP' => IMG_WEBP] as $name => $flag) {
|
|||
|
|
if (($types & $flag) === $flag) {
|
|||
|
|
$formats[] = $name;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
check('Formate lesen', $formats !== [], $formats !== [] ? implode(', ', $formats) : 'keine');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
echo "\n";
|
|||
|
|
|
|||
|
|
foreach (['upload_max_filesize', 'post_max_size', 'memory_limit', 'max_file_uploads', 'max_execution_time'] as $key) {
|
|||
|
|
check($key, true, (string) ini_get($key));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$tmpDir = ini_get('upload_tmp_dir') ?: sys_get_temp_dir();
|
|||
|
|
|
|||
|
|
check('Upload-Temp-Verzeichnis', is_dir($tmpDir) && is_writable($tmpDir), $tmpDir);
|
|||
|
|
|
|||
|
|
echo "\n";
|
|||
|
|
|
|||
|
|
$imgStorage = storage_path('img_storage');
|
|||
|
|
|
|||
|
|
check('storage/ existiert', is_dir(storage_path()), storage_path());
|
|||
|
|
check('img_storage/ existiert', is_dir($imgStorage), $imgStorage);
|
|||
|
|
|
|||
|
|
$writeTarget = is_dir($imgStorage) ? $imgStorage : storage_path();
|
|||
|
|
|
|||
|
|
check('img_storage/ beschreibbar', is_dir($writeTarget) && is_writable($writeTarget), $writeTarget);
|
|||
|
|
|
|||
|
|
if (function_exists('posix_geteuid')) {
|
|||
|
|
$user = posix_getpwuid(posix_geteuid());
|
|||
|
|
check('PHP-Benutzer', true, $user['name'] ?? (string) posix_geteuid());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (is_dir($imgStorage)) {
|
|||
|
|
$owner = fileowner($imgStorage);
|
|||
|
|
$group = filegroup($imgStorage);
|
|||
|
|
|
|||
|
|
$ownerName = function_exists('posix_getpwuid') ? (posix_getpwuid($owner)['name'] ?? (string) $owner) : (string) $owner;
|
|||
|
|
$groupName = function_exists('posix_getgrgid') ? (posix_getgrgid($group)['name'] ?? (string) $group) : (string) $group;
|
|||
|
|
|
|||
|
|
echo str_pad('Eigentümer img_storage', 28) . ': ' . $ownerName . ':' . $groupName . "\n";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
echo "\n";
|
|||
|
|
|
|||
|
|
if ($problems > 0) {
|
|||
|
|
echo $problems . " Problem(e) gefunden. Uploads können dadurch fehlschlagen.\n";
|
|||
|
|
echo "Tipp: Im Docker-Setup korrigiert docker-compose.yml die Rechte beim Start\n";
|
|||
|
|
echo " (chown -R www-data:www-data /var/www/storage).\n";
|
|||
|
|
exit(1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
echo "Alles in Ordnung.\n";
|