Jump to content

displaying multiple text files


mkklepper

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
Link to comment
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..
Link to comment
Share on other sites

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.