Jump to content

Archived

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

mkklepper

displaying multiple text files

Recommended Posts

I'm building a website for a local musician. I want him to be able to update the site himself, upload/delete music, pictures and mini-profiles for his crew. The "edit_crew.php" page uploads a pic and writes information to text files in the dir "uploads/crew_files". My problem is getting the "crew.php" page to loop through the text files and display the info next to the pic. This is a modified version of a script I found on line combined with some of my own. It will display one file fine but gives me error message that the other files don't exist. I'm still new to php and I know it's probably simpler than I'm making it. Please help. (on a diffrent note, all of a sudden I can't copy and paste code in Dreamweaver 8)


$dir = "uploads\\crew_files";
if (is_dir($dir)) {
$dp = open("$dir");
    while(($item = readdir($dp))  ==  true) {
        if($item != "." && $item != ".." ) {
        $file[] = $item;
        $item_name = strtok("$item",'.');
        }
    }
    if($pd == true ) {
    closedir($dp);
    }
}
for($i=0, $i<count($file); $i++ ) {
$npart = $file[$i];
    if(is_file($npart) ) {
    $fp = fopen("$npart", 'rb');
        if($line = fgetcsv($fp, 100, "\t")){
        echo "<div id=\"crew">
                <table width=\"400px\">
                <tr><td rowspan=\"4\"><img src=\"upload/crew_pix/$item_name.jpeg\"></td>
                        <td>$line[0]</td></tr>
                <tr><td>$line[1]</td></tr>
                <tr><td>$line[2]</td></tr>
                <tr><td>$line[3]</td></tr>
                </table>
                </div> ";
        }
    }
}

// mabee i'm on the wrong track

Share this post


Link to post
Share on other sites
try something like this: Main differences is it stores $item_name in an array so you keep track of all the profiles, not just the last one; as well as looking to open and read $dir\$file, instead of $file.

[code]$dir = "uploads\\crew_files";
if (is_dir($dir)) {
$dp = open($dir);
    while ($item = readdir($dp)) {
        if ($item != "." && $item != ".." ) {
        $file[] = $item;
        $item_name[] = strtok($item,'.');
        }
    }
    if($pd) {
    closedir($dp);
    }
}

for ($i=0, $i<count($file); $i++ ) {
$npart = $dir."\\".$file[$i];
    if (is_file($npart)) {
    $fp = fopen($npart, 'rb');
        if( $line = fgetcsv($fp, 100, "\t")){
        echo "<div id=\"crew">
                <table width=\"400px\">
                <tr><td rowspan=\"4\"><img src=\"upload/crew_pix/{$item_name[$i]}.jpeg\"></td>
                <td>$line[0]</td></tr>
                <tr><td>$line[1]</td></tr>
                <tr><td>$line[2]</td></tr>
                <tr><td>$line[3]</td></tr>
                </table>
                </div> ";
        }
    }
}
[/code]

your html might be a bit wonky too..

Share this post


Link to post
Share on other sites

×

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.