How can one effectively retrieve .jpg and .svg files from a specific directory in PHP?

To effectively retrieve .jpg and .svg files from a specific directory in PHP, you can use the glob() function to search for files with the desired extensions. You can then loop through the results to process or display the files as needed.

$directory = 'path/to/directory/';
$jpgFiles = glob($directory . '*.jpg');
$svgFiles = glob($directory . '*.svg');

foreach ($jpgFiles as $jpgFile) {
    // Process or display .jpg files
}

foreach ($svgFiles as $svgFile) {
    // Process or display .svg files
}