Jump to content

Need to load filenames into arrys based on folder...


popalex

Recommended Posts

Hi!

If someone can help me I would be really happy...

 

Is there a way to get an array with name based on the foldername and load the files in that folder into the array?

I need an arry that looks like this:

$art1006=array(

"/img/large/1006/1006.patomella.depp.jpg",

"/img/large/1006/1006.patomella.ethni.jpg",

"/img/large/1006/1006.patomella.lily.jpg",

"/img/large/1006/1006.patomella.opposite.jpg",

"/img/large/1006/1006.patomella.zigzag.jpg"

);

where as you can see the files are in a folder called 1006 - how can I loop all folders in /img/large/ and create an array with a name like $art1006 for each folder and fill them with the files in it?

 

 

This is my code so far:

 

function swForm($artArray, $artid){
$imageName="img".$artid;
$useImage=0; // set default image value (equal to array index number)

if(isset($_REQUEST)){
		while(list($key,$val)=each($_REQUEST)){
  			if(strstr($key,"_img_x")){
   				$useImage=str_replace("_img_x","",$key);
   				break;
  			}
		}
}
echo "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\" id=\"imageSwapperForm\" onsubmit=\"return false\">";
echo "<table><tr><td class=\"abig\">";
echo "<img id=\"$imageName\" src=\"$artArray[$useImage]\" border=\"0\" /></td><td class=\"asmall\">";
for($i=0; $i < count($artArray); $i++){
	echo "<input type=\"image\" name=\"".$i."_img\" value=\"".$i."_img\" src=\"$artArray[$i]\" onclick=\"document.getElementById('$imageName').src=this.src;\" style=\"height:50px;\" /><br />";
}
echo "</td></tr></table></form>";
}

$art1006=array(
"/img/large/1006/1006.patomella.depp.jpg",
"/img/large/1006/1006.patomella.ethni.jpg",
"/img/large/1006/1006.patomella.lily.jpg",
"/img/large/1006/1006.patomella.opposite.jpg",
"/img/large/1006/1006.patomella.zigzag.jpg"
);

$art405=array(
"/img/large/405/405.skoglund.cow27.jpg",
"/img/large/405/405.skoglund.cow28.jpg",
"/img/large/405/405.skoglund.flow52.jpg",
"/img/large/405/405.skoglund.flow53.jpg",
"/img/large/405/405.skoglund.human.jpg",
"/img/large/405/405.skoglund.cow26.jpg"
);
// and so on.... mabye like 30 arrays 
?>

<?php swForm($art1006, '1006')?>
<?php swForm($art405, '405')?>
// and so on.... 

 

 

Thanx in advance // Alex

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.