What potential issues can arise when trying to load SVG files in PHP, especially in the context of user permissions and file extensions?

When loading SVG files in PHP, potential issues can arise with user permissions and file extensions. To ensure that SVG files can be loaded successfully, make sure that the PHP script has the necessary permissions to access the file and that the file extension is allowed by the server configuration.

// Check if the file extension is allowed
$allowed_extensions = ['svg'];
$file_extension = pathinfo($file_path, PATHINFO_EXTENSION);

if (!in_array($file_extension, $allowed_extensions)) {
    die('Invalid file extension');
}

// Check if the PHP script has permission to access the file
if (!is_readable($file_path)) {
    die('Permission denied');
}

// Load the SVG file
$svg_content = file_get_contents($file_path);

// Output the SVG content
header('Content-type: image/svg+xml');
echo $svg_content;