What are some alternative approaches to displaying images from a network directory in PHP to avoid browser access restrictions?

When trying to display images from a network directory in PHP, you may encounter browser access restrictions due to security concerns. One alternative approach to bypass these restrictions is to read the image file contents on the server side and then output them directly to the browser using a PHP script.

<?php
// Path to the image file on the network directory
$imagePath = 'path/to/image.jpg';

// Get the image MIME type
$imageType = mime_content_type($imagePath);

// Set the appropriate content type header
header('Content-Type: ' . $imageType);

// Output the image file content
readfile($imagePath);