Jump to content

How can I specify a .jpg linking to a .wmv download in a simple script?


djkirstyjay

Recommended Posts

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! :D

 

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"; 

?>

 

<?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'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.