01-23-2008, 10:51 PM
|
#3 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 264
Thanks: 2
|
Quote:
Originally Posted by karq
So I'm trying to make a simple php gallery. So far I made the uploading form and file. But when I searched the internet for "How to get those pics on the page" and I found this code;
PHP Code:
<?php
$ava=opendir("failid/");
$i=0;
while ($lisa=readdir($ava)){
if ($lisa !="." && $lisa !="..") {
$files[]=$lisa;
echo '<tr><td><img src="failid/'.$files[$i].'" height="150" width="200"></tr></td>';
$i=$i+1;
}
}
closedir($ava);
?>
It works, but I dont understand it, maybe someone can explane?
|
$ava is handle created with the opendir function that contains the path to where the pictures are stored, the script then loops through the directory using checking to make sure the file string is not either of the dots, then it echos a formated text string with the array, the method used is unnecesary this is a better example
PHP Code:
<?php
$dir = opendir('/path/to/pictures/');
$i = -1;
while($file = readdir($dir))
{
if($file != "." && $file != "..")
{
echo '<tr><td><img src="failid/'.$files[++$i].'" height="150" width="200"></tr></td>';
}
}
closedir($dir);
you could ofcourse use the object oriented method using dir() or glob() as wildhoney is so fond of.
|
|
|
|