popalex Posted March 20, 2007 Share Posted March 20, 2007 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 Link to comment https://forums.phpfreaks.com/topic/43564-need-to-load-filenames-into-arrys-based-on-folder/ Share on other sites More sharing options...
kenrbnsn Posted March 20, 2007 Share Posted March 20, 2007 take a look at the glob() function. Ken Link to comment https://forums.phpfreaks.com/topic/43564-need-to-load-filenames-into-arrys-based-on-folder/#findComment-211575 Share on other sites More sharing options...
popalex Posted March 20, 2007 Author Share Posted March 20, 2007 take a look at the glob() function. Ken Thanks for looking into my problem... I have looked at the glob() function but I dont really understand how to use it to solve my problem... can you please give me an example?? Link to comment https://forums.phpfreaks.com/topic/43564-need-to-load-filenames-into-arrys-based-on-folder/#findComment-211585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.