vetman Posted April 30, 2008 Share Posted April 30, 2008 I can read a dir of images and display the file names. How can I view the images? Any help would be appreciated. I am new to this! This is my code: <?php //Open images directory $dir = dir("../images"); //List files in images directory while (($file = $dir->read()) !== false) { echo "filename: " . $file . "<br />"; } $dir->close(); ?> Quote Link to comment Share on other sites More sharing options...
dooper3 Posted April 30, 2008 Share Posted April 30, 2008 Just use <img src=... as usual in for HTML image displays. Your code should look like this: <?php //Open images directory $dir = dir("../images"); //List files in images directory while (($file = $dir->read()) !== false) { echo '<img src="$file" alt="my image" width="" height="" />'; "; } $dir->close(); ?> Quote Link to comment Share on other sites More sharing options...
vetman Posted April 30, 2008 Author Share Posted April 30, 2008 I modified the code to match yours, all I got was little broken images. So then I put in width , height at 100 and got larger broken images. Not sure what's up! Any suggestions? Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 30, 2008 Share Posted April 30, 2008 Change: <img src="$file" alt="my image" width="" height="" /> To: <img src="../images/' . $file . '" alt="my image" width="" height="" /> =) Quote Link to comment Share on other sites More sharing options...
vetman Posted April 30, 2008 Author Share Posted April 30, 2008 That's it, it works now! I appreciate the help! Thanks Quote Link to comment Share on other sites More sharing options...
vetman Posted April 30, 2008 Author Share Posted April 30, 2008 Okay, I got myself into another bind. I want to put 3 files in a row across the page, then 3 in the next line and so forth. This is the modified code below: <?php //Open images directory $dir = dir("../images"); //List files in images directory while (($file = $dir->read()) !== false) { // how many entries per row $per_row = 3; echo ' <table border=1>'; $count = 0; echo '<img src="../images/' . $file . '" alt="my image" width="" height="" />'; for($x = 0; $x < count($file); $x++) { if($count == 0) { echo ' <tr>'; } echo ' <td>'.$file[$x].'</td>'; $count++; if(($count == $per_row) || ($file[$x] == end($file))) { echo ' </tr>'; $count = 0; } } echo ' </table>'; } $dir->close(); ?> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted May 1, 2008 Share Posted May 1, 2008 <?php //Open images directory $dir = dir("../images"); // this shouldn't be in the while loop $per_row = 3; echo ' <table> <tr>'; $i = 0; // create the rows while (($file = $dir->read()) !== false) { $i++; // close and start another row if the correct number has been displayed if ($i % $per_row == 0) { echo ' </tr> <tr>'; } echo ' <td><img src="../images/' . $file . '" alt="my image" /></td>'; } // finish the current row while ($i % $per_row != 0) { echo ' <td> </td>'; } echo ' </tr> </table>'; } $dir->close(); ?> Quote Link to comment Share on other sites More sharing options...
vetman Posted May 1, 2008 Author Share Posted May 1, 2008 Thank you, I'm working on reading the manual more, I hear you. I'm trying. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.