What is the best practice for displaying the URL of an uploaded image using PHP variables?

When displaying the URL of an uploaded image using PHP variables, it is important to ensure that the URL is properly formatted and secure. One way to achieve this is by concatenating the base URL with the file name of the uploaded image. It is also recommended to sanitize the file name to prevent any potential security vulnerabilities.

// Assuming $imageName contains the file name of the uploaded image
$baseURL = "https://example.com/images/";
$imageURL = $baseURL . htmlspecialchars($imageName);

echo $imageURL;