01-23-2008, 09:46 PM
|
#2 (permalink)
|
|
The Prestige
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
|
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?
|
It's incrementing $i for $files, which is an array, so it's getting the key, which each key is set within each file of $lisa, also you can do an if ( $lisa !="." ) continue; and it should both of them out with lesser bytes of code.
You can do print_r($files) and it should show you each key set between the value.
To me it should look like this:
Code:
array = (
"0" => file,
"1" => file,
"2" => file,
"3" => file
);
To me you should do a foreach iteration upon the array, with $key => $value and then display, though I cannot test it, I'm more experimental type guy, so go for it!
To me it's basically putting all the files names inside an Array, then you can do that foreach and it should output the image from using $files[$i] as since $i is incrementing.
__________________
VillageIdiot can have my babbies ;d
|
|
|
|