Link to a different extension - How to?

My company uses an optical targeting sensor that outputs resultant images as nested .bmp/.svg files. Both files have the exact same file name just different extensions (eg: Image0000.bmp and Image0000.svg) and are written via FTP to an apache webserver.

What I am trying to do is display a ‘gallery’ of the *.bmp files which are sorted newest-first. Then, On-Click, open a new page/tab to display the *.svg file bearing the same name…

Here’s what I’m using to generate the ‘gallery’:

— Code Start —

<?php function newest($a, $b) { return (filemtime($a) > filemtime($b)) ? -1 : 1; } $filepath = 'resultant_images/*'; $bmp_image = glob($filepath . "*.{bmp}", GLOB_BRACE); uasort($bmp_image, "newest"); foreach($bmp_image as $bmp_target) { echo '' . basename($bmp_target) . '
'; } ?>

— Code End —

How do I re-direct to a link with the same file name but using a different extension?

I would do a str_replace on this variable, $bmp_target.

My basis is in infrastructure, not in software/code - how would I implement your suggestion?

w3schools - str_replace
php docs - str_replace

[php]foreach($bmp_image as $bmp_target) {
$bmp_url = str_replace(’.old’, ‘.new’, $bmp_target);
echo “” . basename($bmp_target) . “
”;
}[/php]

—Code Start —

foreach($bmp_image as $bmp_target)
{
$bmp_url = str_replace(’.bmp’, ‘.svg’, $bmp_target);
echo “” . basename($bmp_target) . “
”;
}

— Code End —

That works - with a hitch… The *.svg image opens within the same tab/window. How do I make it open in a new tab/window?

target='_blank'
In the anchor tag [php]something[/php]

DO

Sponsor our Newsletter | Privacy Policy | Terms of Service