djkirstyjay Posted June 4, 2010 Share Posted June 4, 2010 Hi there, I am trying to put together a script that basically lists the the images in a folder on a page and then links to videos of the same name for download. All very simple, apart from the fact that the script is appending the .jpg to the video link, rather than .wmv. Can anyone shed some light how I can change this? From what I can gather, I need to do something with str_replace, but I can't figure out how... Help much appreciated! Here is the code so far... <?php $images = "path/to/videos/covers/"; # Location of thumbs $videos = "path/to/videos/videos/"; # Location of video files $cols = 3; # Number of columns to display if ($handle = opendir($images)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != rtrim($videos,"/")) { $files[] = $file; } } closedir($handle); } $colCtr = 0; echo "<table><tr>"; foreach($files as $file) { if($colCtr %$cols == 0) echo "</tr><tr><td colspan=\"" . $cols . "\"><hr /></td></tr><tr>"; echo "<td align=\"center\"><a href=\"" . $videos . $file . "\"><img src=\"" . $images . $file . "\" /></a><br /><br /><a href=\"" . $videos . $file . ".wmv\">Right click and 'save as' to download video</a></td>"; $colCtr++; } echo "</table>" . "\r\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/203910-how-can-i-specify-a-jpg-linking-to-a-wmv-download-in-a-simple-script/ Share on other sites More sharing options...
dabaR Posted June 4, 2010 Share Posted June 4, 2010 <?php $images = "path/to/videos/covers/"; # Location of thumbs $videos = "path/to/videos/videos/"; # Location of video files $cols = 3; # Number of columns to display if ($handle = opendir($images)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != rtrim($videos,"/")) { $files[] = $file; } } closedir($handle); } $colCtr = 0; echo "<table><tr>"; foreach($files as $file) { if($colCtr %$cols == 0) echo "</tr><tr><td colspan=\"" . $cols . "\"><hr /></td></tr><tr>"; echo "<td align=\"center\"><a href=\"" . $videos . $file . "\"><img src=\"" . $images . $file . "\" /></a><br /><br /><a href=\"" . $videos . str_replace('jpg', 'wmv', $file) . "\">Right click and 'save as' to download video</a></td>"; $colCtr++; } echo "</table>" . "\r\n"; ?> Or use substr($file, 0, -3) . 'wmv' Quote Link to comment https://forums.phpfreaks.com/topic/203910-how-can-i-specify-a-jpg-linking-to-a-wmv-download-in-a-simple-script/#findComment-1067966 Share on other sites More sharing options...
djkirstyjay Posted June 5, 2010 Author Share Posted June 5, 2010 Thanks! That works a treat! Quote Link to comment https://forums.phpfreaks.com/topic/203910-how-can-i-specify-a-jpg-linking-to-a-wmv-download-in-a-simple-script/#findComment-1068376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.