Q:

onclick show the content of the folder clicked-on in a php page

Hi I have the following code of my PHP page that shows me the content of a directory in another server through FTP functions
<?php
$conn = ftp_connect("host") or die("Could not connect");
ftp_login($conn,"username","password");
$files = ftp_nlist($conn,"logs");
foreach($files as $value)
    {
    echo $value;
    }
ftp_close($conn);
?>

this directory contains sub-directories , what I want to do is for each folder in the output result! When I click on it; it shows me the content of it
and I got no clue how to get this to work
this is the link of the result generated but the code above click me
should I use onclick = excuse some PHP function or what? and how to do that?

A:

Try changing your code in your loop to:
echo "<a href=\"test.php?dir={$value}\">{$value}</a>";

Replace your ftp_nlist function call with this:
if ($_GET['dir'] != null) {
    ftp_chdir($conn, "logs/{$_GET['dir']}");
}
else
    ftp_chdir($conn, "logs");
}

$files = ftp_nlist($conn,"");

That will cause the $value to be passed into your page as $_GET['dir'].  
EDIT: Final code should look something like this:
<?php
$conn = ftp_connect("host") or die("Could not connect");
ftp_login($conn,"username","password");

if ($_GET['dir'] != null) {
    ftp_chdir($conn, "logs/{$_GET['dir']}");
}
else
    ftp_chdir($conn, "logs");
}

$files = ftp_nlist($conn,"");

foreach($files as $value) {
    echo "<a href=\"test.php?dir={$value}\">{$value}</a>";
}

ftp_close($conn);
?>

