Jump to content

keeB

Staff Alumni
  • Posts

    1,075
  • Joined

  • Last visited

About keeB

  • Birthday 08/29/1985

Contact Methods

Profile Information

  • Gender
    Male
  • Location
    California

keeB's Achievements

Member

Member (2/5)

0

Reputation

  1. Here's what I came up with Given nick@avari ~/code/php $ ls -l -R .: total 12 drwxr-xr-x 2 nick nick 4096 Jul 13 13:27 audio drwxr-xr-x 2 nick nick 4096 Jul 13 13:27 images -rw-r--r-- 1 nick nick 1166 Jul 13 14:02 test.php ./audio: total 0 -rw-r--r-- 1 nick nick 0 Jul 13 13:27 lol.mp3 ./images: total 0 -rw-r--r-- 1 nick nick 0 Jul 13 13:27 lol.png Output: <a class='myPlayer' href='audio/lol.mp3' style='background-image:url(images/lol.png)'> </a> And... here's the code <?php function directory_to_array($dir) { $ret = array(); $dh = opendir($dir); while (($file=readdir($dh)) !== false) { if ($file != "." && $file != "..") // ignore . and .. $ret[] = $file; } closedir($dh); return $ret; } function match_files($audio, $image) { //assume basename in $audio and $image are the same //merges the two to a new array $ret = array(); foreach ($audio as $name) { $abase = explode(".", $name); foreach ($image as $img) { $ibase = explode(".", $img); if ($abase[0] == $ibase[0]) { $ret[] = array($name, $img); } } } return $ret; } function merge_to_player($input) { foreach ($input as $pair) { print "<a class='myPlayer' href='audio/$pair[0]' style='background-image:url(images/$pair[1])'> </a> "; } } //get the audio directory contents $audio = directory_to_array("audio"); //get the image directory contents $image = directory_to_array("images"); $matched = match_files($audio, $image); merge_to_player($matched); ?>
  2. The addition you'd need to make to your code, then, is to read the images directory in the same fashion as you are the audio directory The other piece of this, which I assume is what you're having trouble with, is understanding how to merge the two items in your array and display them. Take a look at building an array that would look like Array ( [0] => Array ( [0] => song1.mp3 [1] => image1.png ) . . . ) Do you know how to do that?
  3. Linux nerd.
  4. I'm a bad dev, I usually use svn to update my sites I was just adding some lunix flavor to this windows thread.
  5. keeb@urmom:# ftp myhost.org ^ best ftp client in the world.
×
×
  • 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.