Jump to content


Photo

displaying multiple text files


  • Please log in to reply
1 reply to this topic

#1 mkklepper

mkklepper
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 11 October 2006 - 05:04 PM

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

#2 MCP

MCP
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 12 October 2006 - 03:18 AM

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.

$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> ";
        }
    }
}

your html might be a bit wonky too..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users