PDA

View Full Version : Dynamic PHP Directory/Flash slideshow


yubin
03-11-2004, 09:20 AM
ok, I have a PHP page that reads a Directory and automatically hyperlinks the files. I want to pass this info onto a flash slideshow so that the pictures are loaded dynamically from the directory. This way as the pictures need updating all I have to do is insert the new ones and delete the old ones. I assume that the PHP should send the info to a txt file, but I'm a newbie when it comes to this. Any ideas?

Here's my PHP code.

<?
$maindir = "." ;
$mydir = opendir($maindir) ;
$exclude = array( "myPics.php") ;
while($fn = readdir($mydir))
{
if ($fn == $exclude[0] || $fn == $exclude[1]) continue;
echo "<br><a href='$fn'>$fn</a>";
}
closedir($mydir);
?>

Thanks,
Yubin

nathanleyton
03-11-2004, 11:27 AM
You can tell flash to go and get the info from PHP rather than doing anything with a text file. Please search the forums for loadVars(). With this you can pass variables between flash and PHP.

Below is Actionscript

GetPaths = new LoadVars();
GetPaths.onLoad = function(success) {
for (i=0; i<this.total; i++){
//you code to handle the pictures goes here.
// GetPaths["file"+i]
//above is how to get to the paths
}
};
GetPaths.sendAndLoad("http://localhost/yourfile.php", GetPaths, "POST");

below is PHP

<?
$i = 0;
$dir = ".";
$handle=opendir($dir);
while ($file = readdir($handle)) {
if($file=='.'||$file=='..')
continue;
$filetlist [$i] = $file;
$i++;
}
$numRows = count($filetlist);
print "&total=$numRows";
for ($i=0; $i<$numRows; $i++){
echo &file$i= $filetlist [$i];
}
?>


I havn't tested any of this code. but it gives you a clue.

nathan