Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2003
    Location
    London
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    grab filenames from dir, display names from file

    Hi!

    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 [Source]
    Dynamically generated version [Source*]

    *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?
    e.g:

    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

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    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 ...

    PHP Code:
    <?
    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>
    </tr>
    "
    ;
    ?>
    but I dunno if you want to rename them all ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #4
    New Coder
    Join Date
    Jul 2003
    Location
    London
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

    PHP Code:
    <?php 

    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
    pride.com/files/midis/$file/$file2\"><b>"
    ;
    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
            

        }
        
    closedir($handle2); 
    }
    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>";

            } 
        }
        
    closedir($handle); 
    }


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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •