What are common issues with displaying images in PHP when using GET parameters in the URL?

Common issues with displaying images in PHP when using GET parameters in the URL include not properly sanitizing the input, leading to security vulnerabilities such as directory traversal attacks. To solve this issue, it is important to validate and sanitize the input before using it to fetch and display the image.

<?php

// Sanitize the input parameter to prevent directory traversal attacks
$image_name = isset($_GET['image']) ? basename($_GET['image']) : 'default.jpg';

// Display the image
echo '<img src="images/' . $image_name . '" alt="Image">';