irkevin Posted March 23, 2009 Share Posted March 23, 2009 Hi, basically I have one folder[A] with several folders in it.. and in those several folders i have some files.. So what i want is, have a drop down which list all folders in folder[A].... Luckily for me I've been able to do this.. Now, once i select a folder in the dropdown, i want another dropdown to appear with the files in this folder.. Hope that makes sense.. Ask me, i'll elaborate.. here is the code i have so far <?php // define the path as relative $path = "./manga/"; // using the opendir function $dir_handle = @opendir($path) or die("Unable to open $path"); echo "<select id='choose' onchange='selectManga()'>"; echo "<option>Choose a manga</option>"; // running the while loop while ($file = readdir($dir_handle)) { if($file == '.' || $file == '..') { // } else { echo '<option value="'.$path.$file.'" name="'.$file.'">'.$file.'</option>'; $your_file = 'manga/'.$file; } } echo "</select>"; closedir($dir_handle); ?> Well now i need some help guys Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/ Share on other sites More sharing options...
samona Posted March 23, 2009 Share Posted March 23, 2009 You would probably need javascript for that. Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792021 Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 If you don't want to reload the page when the first drop-down is changed then Javascript is the answer. Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792024 Share on other sites More sharing options...
irkevin Posted March 23, 2009 Author Share Posted March 23, 2009 Ok correct for javascript.. but how do i list all files in the selected folder in the dropdown then? Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792029 Share on other sites More sharing options...
irkevin Posted March 23, 2009 Author Share Posted March 23, 2009 I tried this but i doesn't even list something.. <?php // define the path as relative $path = "./manga/"; // using the opendir function $dir_handle = @opendir($path) or die("Unable to open $path"); echo "<select id='choose' onchange='selectManga()'>"; echo "<option>Choose a manga</option>"; // running the while loop while ($file = readdir($dir_handle)) { if($file == '.' || $file == '..') { // } else { echo '<option value="'.$path.$file.'" name="'.$file.'">'.$file.'</option>'; $your_file .= $path.$file.'/'; } } echo "</select>"; closedir($dir_handle); $chapter = $your_file; $chapter_handle = @opendir($chapter) or die("Unable to open $chapter"); //echo "<select id='choose_chap' onchange='selectChap()'>"; //echo "<option>Choose a Chapter</option>"; while ($chapter_file = readdir($chapter_handle)) { echo $chapter_file; } //echo "</select>"; closedir($chapter_handle); ?> Any ideas guys? Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792039 Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 You getting ANYTHING in the dropdown? Even emptyness? Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792041 Share on other sites More sharing options...
irkevin Posted March 23, 2009 Author Share Posted March 23, 2009 in the first dropdown yes, it's listing all the folders, but im getting a hard time to list files in selected folders ..... Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792042 Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 I've had a pay with the code... <?php // define the path as relative $path = "./manga/"; // using the opendir function if ($dir_handle = @opendir($path)) { echo "<select id='choose' onchange='selectManga()'>"; echo "<option>Choose a manga</option>"; // running the while loop while (($file = readdir($dir_handle)) !== false) { if ($file != '.' && $file != '..') { echo '<option value="'.$path.$file.'" name="'.$file.'">'.$file.'</option>'; $your_file .= $path.$file.'/'; } } echo "</select>"; closedir($dir_handle); $chapter = $your_file; if ($chapter_handle = @opendir($chapter)) { //echo "<select id='choose_chap' onchange='selectChap()'>"; //echo "<option>Choose a Chapter</option>"; while ($chapter_file = readdir($chapter_handle)) { echo $chapter_file; } //echo "</select>"; closedir($chapter_handle); } else { echo "Unable to open $chapter"; } } else { echo "Unable to open $path"; } ?> Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792043 Share on other sites More sharing options...
irkevin Posted March 23, 2009 Author Share Posted March 23, 2009 i tried your code and it says unable to open Unable to open ./manga/first_directory/ but the dropdown to list the current existing folders works fine.. Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792046 Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 If it says it's unable to open then there's one error for you already - you need to be able to open a folder before the script will run through. Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792047 Share on other sites More sharing options...
irkevin Posted March 23, 2009 Author Share Posted March 23, 2009 huh? what do you mean? Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792048 Share on other sites More sharing options...
samona Posted March 23, 2009 Share Posted March 23, 2009 I think he's talking about permissions. Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792050 Share on other sites More sharing options...
irkevin Posted March 23, 2009 Author Share Posted March 23, 2009 im testing this locally.. :S Well, if i change this : $chapter = $your_file; to $chapter = "./manga/first_directory/"; then it works.. but i have other folders in the folder manga ... Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792051 Share on other sites More sharing options...
samona Posted March 23, 2009 Share Posted March 23, 2009 im testing this locally.. :S Well, if i change this : $chapter = $your_file; to $chapter = "./manga/first_directory/"; then it works.. but i have other folders in the folder manga ... how about $your_file = "./manga/first_directory/"; $chapter = $your_file; Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792063 Share on other sites More sharing options...
irkevin Posted March 23, 2009 Author Share Posted March 23, 2009 ok in the folder there is 'first_directory', 'second_directory' what if i want to choose the second one? Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792067 Share on other sites More sharing options...
irkevin Posted March 24, 2009 Author Share Posted March 24, 2009 bump no one? Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792395 Share on other sites More sharing options...
irkevin Posted March 24, 2009 Author Share Posted March 24, 2009 I noticed that, when i removed the '.' here $your_file .= $path.$file.'/'; and change it to $your_file = $path.$file.'/'; ... it works. but i read only one folder :S.... how can i switch to the other one :S Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792404 Share on other sites More sharing options...
irkevin Posted March 24, 2009 Author Share Posted March 24, 2009 no one to help? Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792410 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 I'm surprised this hasn't been solved yet. When I get home from work I'll post source I've got on my HD somewhere to scan a web server displaying files and folders with nice little icons. Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792420 Share on other sites More sharing options...
irkevin Posted March 24, 2009 Author Share Posted March 24, 2009 Ok man and thanks for your help i'll be waiting Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792433 Share on other sites More sharing options...
Yesideez Posted March 24, 2009 Share Posted March 24, 2009 It won't be for about 6 hour yet but even if this is solved I'll post it. I'll PM you either way to let you know I've posted it. Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-792435 Share on other sites More sharing options...
irkevin Posted March 25, 2009 Author Share Posted March 25, 2009 Here's what i've been looking for http://www.mu-anime.com/manga_folder.php Looks like i'm almost done with it.. here is the code <?php /*####################################################### * * THIS BLOCK OF CODE IS TO FETCH THE FIRST FOLDERS * AND OUTPUT THEM IN OUR DROP DOWN MENU * *********************************************************/ $path = "manga/"; $narray = array(); if ($dir_handle = @opendir($path)) { $i = 0; while (($file = readdir($dir_handle)) !== false) { if ($file != '.' && $file != '..') { $narray[$i] = $file; $i++; } }// end while sort($narray); for($i=0; $i < sizeof($narray); $i++) { $folder = $_GET['folder']; if($folder == $path.$narray[$i]) { $output .= '<option value="manga_folder.php?folder='.$path.$narray[$i].'" selected="selected">'. $narray[$i]. '</option>'; } else { $output .= '<option value="manga_folder.php?folder='.$path.$narray[$i].'">'.$narray[$i].'</option>'; } }// end for loop closedir($dir_handle); } // end dir handle /*####################################################### * * THIS BLOCK OF CODE IS TO FETCH THE SUB FOLDERS * AND OUTPUT THEM IN OUR SECOND DROP DOWN MENU * *********************************************************/ $folder = $_GET['folder']; $thepath = $folder; if ($the_handle = @opendir($thepath)) { while (($thefile = readdir($the_handle)) !== false) { if ($thefile != '.' && $thefile != '..') { if($_GET['chapter'] == $thefile) { $list .= '<option value="manga_folder.php?folder='.$thepath.'&chapter='.$thefile.'" selected="selected">'.$thefile. '</option>'; } else { $list .= '<option value="manga_folder.php?folder='.$thepath.'&chapter='.$thefile.'"> '.$thefile. '</option>'; } } } closedir($the_handle); } /*####################################################### * * THIS BLOCK OF CODE IS TO READ ALL THE FILES * AND OUTPUT THEM AS PICTURE TO READ * *********************************************************/ $chapter = $_GET['folder'].'/'.$_GET['chapter']; $carray = array(); if(isset($chapter)) { if ($the_chapter = @opendir($chapter)) { $i = 0; while (($TheChapter = readdir($the_chapter)) !== false) { if ($TheChapter != '.' && $TheChapter != '..') { $carray[$i] = $TheChapter; $i++; } }// end while sort($carray); for($i = 0; $i < sizeof($carray); $i++) { if(isset($_GET['chapter'])) { $page .= '<option value="'.$chapter.'/'.$carray[$i].'"> Page No:'.$i.'</option>'; } else { $page .= '<option value="'.$chapter.'/'.$carray[$i].'"></option>'; } $gallery .= 'galleryarray['.$i.']="'.$carray[$i].'";'; $jsarray = 'var galleryarray=new Array();'; } closedir($the_chapter); }// end handle } ?> I know it might look messy to you guys I'm only good with php and mysql.. and it the first time i've been able to manage something with folders, subfolders and files.. Below is the javascript to get the dropdown to go to the selected folders and Files.. <script type="text/javascript"> <?php echo $jsarray;?> <?php echo $gallery;?> var curimg = 0 function rotateimages() { document.getElementById("slideshow").setAttribute("src", "<?php echo $chapter;?>/"+galleryarray[curimg]) document.getElementById('page').options[curimg+1].setAttribute('selected','selected'); if(curimg < galleryarray.length-1) { curimg = curimg+1; } else { curimg = 0; document.getElementById("slideshow").style.cursor = 'default'; } } function selectManga() { var folder = document.getElementById('choose'); for(i=0;i < folder.selectedIndex; i++) { if(folder.selectedIndex) { document.location = folder.value; } } } function selectChapter() { var chapter = document.getElementById('chapters'); for(i=0; i < chapter.selectedIndex; i++) { if(chapter.selectedIndex) { document.location = chapter.value; } } } function changePage() { var MyPage = document.getElementById('page'); for(i=0; i < MyPage.selectedIndex; i++) { if(MyPage.selectedIndex) { document.getElementById('slideshow').src = MyPage.value; } } } </script> Oh, if you have some modification that would make the script better, do share plz .. Link to comment https://forums.phpfreaks.com/topic/150757-help-with-listing-folders-and-files/#findComment-793780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.