Jump to content

help with listing folders and files


irkevin

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.