I have following code to get directories of folder ,
<?php
$path = 'templates';
$files = scandir($path);
foreach($files as $result) {
if ($result != "." && $result != ".." && $result != "desktop.ini")
{
echo '<img src="img/folder.png" width="40px"><a name="'.$result.'" class = "folderLink" href="#">'.$result.'</a> <input type="hidden" name="'.$result.'" value="'.$result.'"></img><br><div class="fileListInner"></div>';
}
}
?>
Above code returns dynamic number of folder names. This code is working fine and displayed folder list on success. Here is my form,
<form id="t-files">
<a style="margin-left:160px;" class="list-directories" href="#">Select File Path</a><br><br>
<div id="fileList"></div>
</form>
Now I want to go inside each folder and list sub folders. To do it I get class name of each link and on click even call ajax function. here is the code,
// load directories - inner (settings)
$(document).on("click",".folderLink",function(e){
e.preventDefault();
$.ajax({
type: 'post',
url: 'list-directories-inner.php',
dataType: 'text',
data: $('#t-files').serialize(),
success: function (data) {
$('#fileList').html(data);
}
});
exit();
});
And list-directories-inner.php file,
<?php
foreach ($_POST as $key => $value){
echo "".$key."<br>";
}
$path = 'templates';
$files = scandir($path);
foreach($files as $result) {
if ($result != "." && $result != ".." && $result != "desktop.ini")
{
// echo '<img src="img/folder.png" width="40px"><a href="#">'.$result.'</a></img><br>';
}
}
?>
How can I pass clicked link( hidden input) name value instead of pass all hidden values? Because in the list-directories-inner.php file I want to get clicked link value to set path. Something like 'templates/post value'. I'm thinking for hours. Please help.