What are the best practices for handling paths to Flash files in PHP?

When handling paths to Flash files in PHP, it is important to ensure that the paths are properly sanitized and validated to prevent any security vulnerabilities or file inclusion attacks. One best practice is to use the realpath() function to resolve the full path of the Flash file before including or accessing it.

// Sanitize and validate the Flash file path
$flashFilePath = '/path/to/flash/file.swf';

// Get the full path of the Flash file
$realFlashFilePath = realpath($flashFilePath);

// Check if the file exists and is a valid Flash file
if ($realFlashFilePath && pathinfo($realFlashFilePath, PATHINFO_EXTENSION) == 'swf') {
    // Include or access the Flash file
    echo '<embed src="' . $realFlashFilePath . '" type="application/x-shockwave-flash">';
} else {
    echo 'Invalid Flash file path';
}