Page 1 of 1

while loop

Posted: Wed Jul 23, 2003 4:10 am
by brionvega
Hi all,

first the php code :

<?php
while(list($name, $value) = each($HTTP_POST_VARS))
{
$$name = $value;
}

$myvar = $choix;
$myext = $extent;
$rep=opendir($myvar);
$fichiers="";

while ($nomfichier=readdir($rep)){
if(substr($nomfichier,-3)==$myext) {
$fichiers .= ",".substr($nomfichier, 0);
}
}


echo "listeMP3=".urlencode(substr($fichiers,1));
closedir($rep);
?>

I am passing variables from Flash to PHP and back. The value of $myvar is the path to a folder ("images/folder1/")
PHP is then browsing the folder and sends back to Flash the filenames with the extention $myext (can be .jpg, .gif...).

What I would like to do and don't no how is the following : Depending on the users choice (in The Flash interface), php should not only browse 1 folder, but 2. Like :
$myvar="images/folder1/" and $myvar2="images/folder2/". Now the question : Do I have to build to seperate while loops for each variable or is there a way to build that in the loop I have.

Thank you very much for your help !!!!!!

Posted: Wed Jul 23, 2003 5:26 am
by Tubbietoeter
You can declare $myvar as an array and loop through it:

$myvar[0]="/path1/";
$myvar[1]="/path2/";

foreach ($myvar as $key => $path) {

$rep=opendir($path);
$fichiers="";

while ($nomfichier=readdir($rep)){
if(substr($nomfichier,-3)==$myext) {
$fichiers .= ",".substr($nomfichier, 0);
}
}




}

Posted: Wed Jul 23, 2003 5:30 am
by brionvega
Thank you very much for your help and your quick response.