Jump to content

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


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'

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.