sle09 Posted June 28, 2008 Share Posted June 28, 2008 how would i make it also check subdirectorys and use them $dir=opendir($file_dir); $xml_string= array(); while ($file=readdir($dir)) { if(substr($file, -3) == "jpg" || substr($file, -4) == "jpeg" ){ $tmp_str = '<image img="'.$file_dir.'/'.$file.'" '; if($show_titles){ $file_title=substr($file, $omit_chars, strpos($file, ".")-$omit_chars); $tmp_str .= 'caption="'.$file_title.'" '; } if($link_to_image){ $link_title=substr($file, $omit_chars, strpos($file, ".")-$omit_chars); $tmp_str .= 'link="'.$file_dir.'/'.$file.'" target="_blank"'; } $tmp_str .=" />"; array_push($xml_string, $tmp_str); } } sort($xml_string); for($i=0; $i<count($xml_string); $i++){ print $xml_string[$i]; } closedir($dir); Link to comment https://forums.phpfreaks.com/topic/112299-subdirectorys/ Share on other sites More sharing options...
ratcateme Posted June 28, 2008 Share Posted June 28, 2008 you could turn it into a function like this <?php fucntion opendir($file_dir){ $dir=opendir($file_dir); $xml_string= array(); while ($file=readdir($dir)) { if(is_dir($file_dir.'/'.$file)){ opendir($file_dir.'/'.$file); // go into subdir } elseif(substr($file, -3) == "jpg" || substr($file, -4) == "jpeg" ){ $tmp_str = '<image img="'.$file_dir.'/'.$file.'" '; if($show_titles){ $file_title=substr($file, $omit_chars, strpos($file, ".")-$omit_chars); $tmp_str .= 'caption="'.$file_title.'" '; } if($link_to_image){ $link_title=substr($file, $omit_chars, strpos($file, ".")-$omit_chars); $tmp_str .= 'link="'.$file_dir.'/'.$file.'" target="_blank"'; } $tmp_str .=" />"; array_push($xml_string, $tmp_str); } } sort($xml_string); for($i=0; $i<count($xml_string); $i++){ print $xml_string[$i]; } closedir($dir); } Scott. Link to comment https://forums.phpfreaks.com/topic/112299-subdirectorys/#findComment-576557 Share on other sites More sharing options...
LinuxForce Posted June 28, 2008 Share Posted June 28, 2008 Here's another way http://www.tech-funda.com/?p=28 I use it for download forms on websites that need upload functions or a download database. Link to comment https://forums.phpfreaks.com/topic/112299-subdirectorys/#findComment-576568 Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 While the function below doesn't encompass your own code, it should be easy to see where each part goes. This function uses recursion to go through all subdirectories. The depth parameter means how deep it should go (ie. how many subdirectories it should look in). function viewcontents($path, $depth) { if (is_dir($path)) { $handle = @opendir($path); if (!$handle) exit("No permission to access.<br />"); while (false !== ($file = @readdir($handle))) { $tfile = str_replace("//", "/", $path."/".$file); if (strlen($file) < 3) continue; if(is_dir($tfile)) { echo "DIR: ".$tfile."<br />"; recursiveDelete($tfile, 0); } else { echo "FILE: ".$tfile."<br />"; } } } if ($depth > 1) viewcontents($path, --$depth); } Link to comment https://forums.phpfreaks.com/topic/112299-subdirectorys/#findComment-576655 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.