View Full Version : grab filenames from dir, display names from file

09-10-2003, 12:17 AM

I have made a script to open a set of directories grab filenames from each one under the correct directory (inspired by EthanX's thread)

But now I want to improve them

Old version (http://www.thedevilspride.com/index.php?page=midis) [Source (http://www.thedevilspride.com/temp/midis.txt)]
Dynamically generated version (http://www.thedevilspride.com/index.php?page=midis-php) [Source* (http://www.thedevilspride.com/temp/midis-php.txt)]

*use view source if your browser opens the file

As you can see, They aren't displayed the same.
Could I add the true title using another file?

Midi file.mid|True name of file
another file.mid|another midi file
third midi file.mid|yet another midi file

and have that replace all the filenames to names of each file?
Also could anyone help me get the filesize working?

Sorry if this didn't make any sence, this is confusing

Thanks :)

09-10-2003, 04:52 AM
if you were to rename all of your midi's as per dan_dan , eg with underscores (or whatever) where spaces should be then you could do ...

echo "
<td valign=\"top\" width=\"65%\"><a href=\"http://www.thedevilspride.com/files/midis/$file/$file2\"><b>
" . str_replace( '_' , '' , $file2) . "</b></a></td>
<td width=\"5%\">&nbsp;</td>
<td align=\"right\" valign=\"top\" width=\"35%\">65 kb</td>

but I dunno if you want to rename them all ?

09-10-2003, 12:54 PM
you could use a lookup file reasonably easily by running an array when you read it

$file_names = array();
$lines = file ('http://www.example.com/true_names.txt');
foreach ($lines as $line_num => $line)
$parts = trim(explode('|',$line);
$file_names[$parts[0]] = $parts[1];

with a file like
dan_dan.mid | Dan Dan Kokoro
next.mid | Next Name

it should yield an array
$filenames['dan_dan.mid'] = 'Dan Dan Kokoro'; etc

so you could just use the dynamic filename to output the value -

echo $file_names[$file];


pseudo code - didn't get as far as scanning your source - may well need amends

09-10-2003, 09:09 PM
Thanks for the replies :)

Íkii I think i'll go along with your way.
Although I couldn't get it to work, even using it the way you said to :(

Heres my code;
is there any way to combine them together to they work?


if ($handle = opendir('/path/to/files')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {

// Begin - display dir names

echo " <tr>";
echo " <td valign=\"top\" colspan=\"3\" width=\"95%\">$file</td>";
echo " </tr>";

// End

if ($handle2 = opendir('/path/to/files/' . $file)) {
while (false !== ($file2 = readdir($handle2))) {
if ($file2 != "." && $file2 != ".." && $file2 != "index.html") {

// Begin - echo midi files

echo " <tr>";
echo " <td valign=\"top\" width=\"65%\"><a href=\"http://www.thedevils
echo " $file2</b></a></td>";
echo " <td width=\"5%\">&nbsp;</td>";
echo " <td align=\"right\" valign=\"top\" width=\"35%\">65 kb</td>";
echo " </tr>";

// End
echo "<tr>";
echo " <td valign=\"top\" width=\"65%\">&nbsp;</td>";
echo " <td width=\"5%\">&nbsp;</td>";
echo " <td align=\"right\" valign=\"top\" width=\"35%\">&nbsp;</td>";
echo " </tr>";



I have looked at different ways of replacing text in arrays although i'm not too sure how to change my code to use them.