Read all images from subdirectories

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jd57
Forum Newbie
Posts: 13
Joined: Tue Apr 21, 2009 8:04 am

Read all images from subdirectories

Post by jd57 »

Hi can someone tell me how I can make this script to show all images that are found in a bunch of subdirectorie.
Presentely it only reads from the SEArchive and display only images that are false in mysql database

Code: Select all

 
<?PHP
 
mysql_connect("localhost", "ixxx_jxxx", "xxx") or die(mysql_error());
 
mysql_select_db("xxxx") or die(mysql_error());
 
$sql = "SELECT * FROM `ihsreg` WHERE approve!='TRUE' ORDER BY `Bloom_Name` ASC";
$results = mysql_query($sql);
$column = 1;
 
print "<table>";
while(($row = mysql_fetch_assoc($results)) !== false) {     
    if ($column == 1) { 
        print "<tr>"; 
    }
    
    print '
        <td>
            <a href="http://www.Mysite/approvalpending/RegPending1.php?search=' . $row['Bloom_Name'] . '">
 
                <img src="http://www.Mysite/SEArchive/' . $row['Bloom_Name'] . '.jpg" width="130" height="130" border="0">
            <BR></a>' .$row['Bloom_Name'] . '
 
        </td>';
        
    if ($column == 6) { 
        print "</tr>"; 
        $column = 0; 
    }
    
    $column++;
} 
 
if ($column < 5) {
    while ($column < 5) {
        $column++;
        echo "
            <td>&nbsp;</td>";
    }
    
    echo "</tr>";
}
 
print "</table>";
Last edited by Benjamin on Wed May 27, 2009 2:15 pm, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Read all images from subdirectories

Post by pickle »

You're just pulling this stuff out of the database right? You're not actually reading the filesystem?

What does $row['Bloom_name'] contain? The way you've hardcoded in the image tag, it looks like it's either just a filename without an extension, or a path without an extension. So:

$row['Bloom_name'] = 'cats', would give you the image path of http://www.Mysite/SEArchive/cats.jpg
$row['Bloom_name'] = 'animals/cats/persian' would give you the image path of http://www.Mysite/SEArchive/animals/cats/persian.jpg
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply