Fixing Broken Thumbnails\n"; // Get all images with thumbnail filenames $images = $db->fetchAll("SELECT id, filename, thumbnail_filename FROM images WHERE thumbnail_filename IS NOT NULL AND thumbnail_filename != ''"); echo "

Found " . count($images) . " images with thumbnail filenames

\n"; $fixed = 0; $removed = 0; foreach ($images as $image) { $thumbPath = $thumbsDir . '/' . $image['thumbnail_filename']; if (!file_exists($thumbPath)) { echo "

Thumbnail file missing for image ID {$image['id']}: {$image['thumbnail_filename']}

\n"; // Remove thumbnail filename from database (fallback to original) $db->update('images', ['thumbnail_filename' => null], 'id = ?', [$image['id']]); echo "

✓ Removed thumbnail filename for image ID {$image['id']}

\n"; $removed++; } else { echo "

✓ Thumbnail exists for image ID {$image['id']}

\n"; $fixed++; } } echo "

Summary

\n"; echo "

Images with valid thumbnails: {$fixed}

\n"; echo "

Broken thumbnail entries removed: {$removed}

\n"; // Test thumbnail generation on a sample image $testImages = $db->fetchAll("SELECT id, filename FROM images WHERE thumbnail_filename IS NULL LIMIT 3"); if (!empty($testImages)) { echo "

Testing Thumbnail Generation

\n"; foreach ($testImages as $image) { $sourcePath = '../uploads/images/' . $image['filename']; $thumbFilename = 'thumb_' . $image['filename']; $thumbPath = $thumbsDir . '/' . $thumbFilename; if (file_exists($sourcePath)) { echo "

Testing thumbnail generation for: {$image['filename']}

\n"; // Include the thumbnail generation function require_once 'upload_image.php'; if (generateThumbnail($sourcePath, $thumbPath)) { // Update database with new thumbnail filename $db->update('images', ['thumbnail_filename' => $thumbFilename], 'id = ?', [$image['id']]); echo "

✓ Successfully generated thumbnail for image ID {$image['id']}

\n"; } else { echo "

✗ Failed to generate thumbnail for image ID {$image['id']}

\n"; } } else { echo "

✗ Source file not found: {$image['filename']}

\n"; } } } echo "

← Back to Editor

\n"; ?>