Navigate through webdirectory in Browser










-2














I'm currently trying the following:



I want to navigate through my webdirectory in the browser. So lets say I have a folder here: /var/www and I now want to be able, to navigate trough the folder structure on a site I make myself. So having clickable folders, and in that folders again folders, files etc., which should be all be downloadable.
I already thought about the RecursiveDirectoryIterator, but as this one only shows all file names at once, it's not what I need (as I want only the folders in the directory I'm currently in, and then if I click on a directory, being in there again etc (just like I would write (on the server): cd test ls cd folder_in_test ls, and so on, with the possibility to go back on the higher-level folder of course. Just the same behaviour as e.g. here on dropbox or on Google Drive and so on, I hope you know what I mean.



As I said I tried something like that:



<?php

$path = realpath('/etc');

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object)
echo "$namen";


?>


But it's just listing all files recursively from the complete var/www-folder, and this is not what I want.










share|improve this question























  • Why the downvote?
    – user5638730
    Apr 15 '16 at 6:39















-2














I'm currently trying the following:



I want to navigate through my webdirectory in the browser. So lets say I have a folder here: /var/www and I now want to be able, to navigate trough the folder structure on a site I make myself. So having clickable folders, and in that folders again folders, files etc., which should be all be downloadable.
I already thought about the RecursiveDirectoryIterator, but as this one only shows all file names at once, it's not what I need (as I want only the folders in the directory I'm currently in, and then if I click on a directory, being in there again etc (just like I would write (on the server): cd test ls cd folder_in_test ls, and so on, with the possibility to go back on the higher-level folder of course. Just the same behaviour as e.g. here on dropbox or on Google Drive and so on, I hope you know what I mean.



As I said I tried something like that:



<?php

$path = realpath('/etc');

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object)
echo "$namen";


?>


But it's just listing all files recursively from the complete var/www-folder, and this is not what I want.










share|improve this question























  • Why the downvote?
    – user5638730
    Apr 15 '16 at 6:39













-2












-2








-2







I'm currently trying the following:



I want to navigate through my webdirectory in the browser. So lets say I have a folder here: /var/www and I now want to be able, to navigate trough the folder structure on a site I make myself. So having clickable folders, and in that folders again folders, files etc., which should be all be downloadable.
I already thought about the RecursiveDirectoryIterator, but as this one only shows all file names at once, it's not what I need (as I want only the folders in the directory I'm currently in, and then if I click on a directory, being in there again etc (just like I would write (on the server): cd test ls cd folder_in_test ls, and so on, with the possibility to go back on the higher-level folder of course. Just the same behaviour as e.g. here on dropbox or on Google Drive and so on, I hope you know what I mean.



As I said I tried something like that:



<?php

$path = realpath('/etc');

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object)
echo "$namen";


?>


But it's just listing all files recursively from the complete var/www-folder, and this is not what I want.










share|improve this question















I'm currently trying the following:



I want to navigate through my webdirectory in the browser. So lets say I have a folder here: /var/www and I now want to be able, to navigate trough the folder structure on a site I make myself. So having clickable folders, and in that folders again folders, files etc., which should be all be downloadable.
I already thought about the RecursiveDirectoryIterator, but as this one only shows all file names at once, it's not what I need (as I want only the folders in the directory I'm currently in, and then if I click on a directory, being in there again etc (just like I would write (on the server): cd test ls cd folder_in_test ls, and so on, with the possibility to go back on the higher-level folder of course. Just the same behaviour as e.g. here on dropbox or on Google Drive and so on, I hope you know what I mean.



As I said I tried something like that:



<?php

$path = realpath('/etc');

$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object)
echo "$namen";


?>


But it's just listing all files recursively from the complete var/www-folder, and this is not what I want.







php file directory-listing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 5:13









Cœur

17.4k9102143




17.4k9102143










asked Apr 15 '16 at 6:26









user5638730

1701315




1701315











  • Why the downvote?
    – user5638730
    Apr 15 '16 at 6:39
















  • Why the downvote?
    – user5638730
    Apr 15 '16 at 6:39















Why the downvote?
– user5638730
Apr 15 '16 at 6:39




Why the downvote?
– user5638730
Apr 15 '16 at 6:39












2 Answers
2






active

oldest

votes


















1














<?php
$dir = '/path/to/my/directory';
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";




?>
<div class="media-manager">
<?php echo $output;?>
</div>

<script>
$(".dir-div").on("click",function()
$.ajax(
url:'somephp.php',
method:'POST',
data:data:$(this).attr("data-key")
success:function(data)
$(".media-manager").html(data);

)
)
</script>


IN somephp.php



<?php
$dir =$_POST['data'];
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";



echo $output
?>





share|improve this answer




















  • This works (except a comma you forgot), only added the nearly same code in your "somephp.php" file, so i can go recursively in the folders, not only one folder, and then theres no clickable folder any more. I just have one problem now: I can visit the complete file system now, so I can also go out of var/www, so for example navigate to /etc, do you know how to avoid that?
    – user5638730
    Apr 15 '16 at 17:31










  • do you have any idea?
    – user5638730
    Apr 16 '16 at 8:40










  • you can keep if condition if(substr($_POST['data'], 0, strlen("yourwebroot")) ==="yourwebroot") $dir =$_POST['data']; else $dir ="path/to/webroot";
    – Naisa purushotham
    Apr 16 '16 at 17:47










  • yeah, I thought about something like that as well, but then there is one problem: if somebody knows how to deal with html then it's no problem to go to another directory anyway because they can just press f12 in chrome for developer tools and then they simply change the content of data-key to the folder they want and they're in.... What to do know?
    – user5638730
    Apr 17 '16 at 5:26










  • if they change data-key also not a problem, for that if condition will work like this, for example, your document root is "xyz", now you want allow only xyz/images folder. datakey always like this : images/folder1,images/folder2,images/file.jpg... if condition will check directory is starting with images or not , if yes then it will go to sub directory(images/folder1/folder5), other wise it will show only images folder. i hope it will helpful..
    – Naisa purushotham
    Apr 18 '16 at 5:05


















0














use scandir() php in built function. it will return particular files and dirname in that locatoin



 $dir = '/path/to/my/directory';
$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

//your code here




//This is one more example to get files recursively.

function dirToArray($dir)

$result = array();

$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (!in_array($value,array(".","..")))

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);

else

$result = $value;




return $result;






share|improve this answer




















  • but I see it right, that this only lists the files once, and when clicking on a folder, what hapens then? Or am I wrong?
    – user5638730
    Apr 15 '16 at 6:54










  • use ajax call and get sub folder list, display the result, if folder add some class, by using jquery click event raise ajax call
    – Naisa purushotham
    Apr 15 '16 at 6:57











  • Could you tell me how such an ajax call is working? Seldom worked with AJAX....
    – user5638730
    Apr 15 '16 at 7:32










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36639699%2fnavigate-through-webdirectory-in-browser%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














<?php
$dir = '/path/to/my/directory';
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";




?>
<div class="media-manager">
<?php echo $output;?>
</div>

<script>
$(".dir-div").on("click",function()
$.ajax(
url:'somephp.php',
method:'POST',
data:data:$(this).attr("data-key")
success:function(data)
$(".media-manager").html(data);

)
)
</script>


IN somephp.php



<?php
$dir =$_POST['data'];
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";



echo $output
?>





share|improve this answer




















  • This works (except a comma you forgot), only added the nearly same code in your "somephp.php" file, so i can go recursively in the folders, not only one folder, and then theres no clickable folder any more. I just have one problem now: I can visit the complete file system now, so I can also go out of var/www, so for example navigate to /etc, do you know how to avoid that?
    – user5638730
    Apr 15 '16 at 17:31










  • do you have any idea?
    – user5638730
    Apr 16 '16 at 8:40










  • you can keep if condition if(substr($_POST['data'], 0, strlen("yourwebroot")) ==="yourwebroot") $dir =$_POST['data']; else $dir ="path/to/webroot";
    – Naisa purushotham
    Apr 16 '16 at 17:47










  • yeah, I thought about something like that as well, but then there is one problem: if somebody knows how to deal with html then it's no problem to go to another directory anyway because they can just press f12 in chrome for developer tools and then they simply change the content of data-key to the folder they want and they're in.... What to do know?
    – user5638730
    Apr 17 '16 at 5:26










  • if they change data-key also not a problem, for that if condition will work like this, for example, your document root is "xyz", now you want allow only xyz/images folder. datakey always like this : images/folder1,images/folder2,images/file.jpg... if condition will check directory is starting with images or not , if yes then it will go to sub directory(images/folder1/folder5), other wise it will show only images folder. i hope it will helpful..
    – Naisa purushotham
    Apr 18 '16 at 5:05















1














<?php
$dir = '/path/to/my/directory';
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";




?>
<div class="media-manager">
<?php echo $output;?>
</div>

<script>
$(".dir-div").on("click",function()
$.ajax(
url:'somephp.php',
method:'POST',
data:data:$(this).attr("data-key")
success:function(data)
$(".media-manager").html(data);

)
)
</script>


IN somephp.php



<?php
$dir =$_POST['data'];
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";



echo $output
?>





share|improve this answer




















  • This works (except a comma you forgot), only added the nearly same code in your "somephp.php" file, so i can go recursively in the folders, not only one folder, and then theres no clickable folder any more. I just have one problem now: I can visit the complete file system now, so I can also go out of var/www, so for example navigate to /etc, do you know how to avoid that?
    – user5638730
    Apr 15 '16 at 17:31










  • do you have any idea?
    – user5638730
    Apr 16 '16 at 8:40










  • you can keep if condition if(substr($_POST['data'], 0, strlen("yourwebroot")) ==="yourwebroot") $dir =$_POST['data']; else $dir ="path/to/webroot";
    – Naisa purushotham
    Apr 16 '16 at 17:47










  • yeah, I thought about something like that as well, but then there is one problem: if somebody knows how to deal with html then it's no problem to go to another directory anyway because they can just press f12 in chrome for developer tools and then they simply change the content of data-key to the folder they want and they're in.... What to do know?
    – user5638730
    Apr 17 '16 at 5:26










  • if they change data-key also not a problem, for that if condition will work like this, for example, your document root is "xyz", now you want allow only xyz/images folder. datakey always like this : images/folder1,images/folder2,images/file.jpg... if condition will check directory is starting with images or not , if yes then it will go to sub directory(images/folder1/folder5), other wise it will show only images folder. i hope it will helpful..
    – Naisa purushotham
    Apr 18 '16 at 5:05













1












1








1






<?php
$dir = '/path/to/my/directory';
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";




?>
<div class="media-manager">
<?php echo $output;?>
</div>

<script>
$(".dir-div").on("click",function()
$.ajax(
url:'somephp.php',
method:'POST',
data:data:$(this).attr("data-key")
success:function(data)
$(".media-manager").html(data);

)
)
</script>


IN somephp.php



<?php
$dir =$_POST['data'];
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";



echo $output
?>





share|improve this answer












<?php
$dir = '/path/to/my/directory';
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";




?>
<div class="media-manager">
<?php echo $output;?>
</div>

<script>
$(".dir-div").on("click",function()
$.ajax(
url:'somephp.php',
method:'POST',
data:data:$(this).attr("data-key")
success:function(data)
$(".media-manager").html(data);

)
)
</script>


IN somephp.php



<?php
$dir =$_POST['data'];
$cdir = scandir($dir);
$output="";
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$output.="<div class='dir-div' data-key='".$dir . DIRECTORY_SEPARATOR . $value."'>$value</div>";


else

$output.="<div class='file-div'>$value</div>";



echo $output
?>






share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 15 '16 at 7:49









Naisa purushotham

749615




749615











  • This works (except a comma you forgot), only added the nearly same code in your "somephp.php" file, so i can go recursively in the folders, not only one folder, and then theres no clickable folder any more. I just have one problem now: I can visit the complete file system now, so I can also go out of var/www, so for example navigate to /etc, do you know how to avoid that?
    – user5638730
    Apr 15 '16 at 17:31










  • do you have any idea?
    – user5638730
    Apr 16 '16 at 8:40










  • you can keep if condition if(substr($_POST['data'], 0, strlen("yourwebroot")) ==="yourwebroot") $dir =$_POST['data']; else $dir ="path/to/webroot";
    – Naisa purushotham
    Apr 16 '16 at 17:47










  • yeah, I thought about something like that as well, but then there is one problem: if somebody knows how to deal with html then it's no problem to go to another directory anyway because they can just press f12 in chrome for developer tools and then they simply change the content of data-key to the folder they want and they're in.... What to do know?
    – user5638730
    Apr 17 '16 at 5:26










  • if they change data-key also not a problem, for that if condition will work like this, for example, your document root is "xyz", now you want allow only xyz/images folder. datakey always like this : images/folder1,images/folder2,images/file.jpg... if condition will check directory is starting with images or not , if yes then it will go to sub directory(images/folder1/folder5), other wise it will show only images folder. i hope it will helpful..
    – Naisa purushotham
    Apr 18 '16 at 5:05
















  • This works (except a comma you forgot), only added the nearly same code in your "somephp.php" file, so i can go recursively in the folders, not only one folder, and then theres no clickable folder any more. I just have one problem now: I can visit the complete file system now, so I can also go out of var/www, so for example navigate to /etc, do you know how to avoid that?
    – user5638730
    Apr 15 '16 at 17:31










  • do you have any idea?
    – user5638730
    Apr 16 '16 at 8:40










  • you can keep if condition if(substr($_POST['data'], 0, strlen("yourwebroot")) ==="yourwebroot") $dir =$_POST['data']; else $dir ="path/to/webroot";
    – Naisa purushotham
    Apr 16 '16 at 17:47










  • yeah, I thought about something like that as well, but then there is one problem: if somebody knows how to deal with html then it's no problem to go to another directory anyway because they can just press f12 in chrome for developer tools and then they simply change the content of data-key to the folder they want and they're in.... What to do know?
    – user5638730
    Apr 17 '16 at 5:26










  • if they change data-key also not a problem, for that if condition will work like this, for example, your document root is "xyz", now you want allow only xyz/images folder. datakey always like this : images/folder1,images/folder2,images/file.jpg... if condition will check directory is starting with images or not , if yes then it will go to sub directory(images/folder1/folder5), other wise it will show only images folder. i hope it will helpful..
    – Naisa purushotham
    Apr 18 '16 at 5:05















This works (except a comma you forgot), only added the nearly same code in your "somephp.php" file, so i can go recursively in the folders, not only one folder, and then theres no clickable folder any more. I just have one problem now: I can visit the complete file system now, so I can also go out of var/www, so for example navigate to /etc, do you know how to avoid that?
– user5638730
Apr 15 '16 at 17:31




This works (except a comma you forgot), only added the nearly same code in your "somephp.php" file, so i can go recursively in the folders, not only one folder, and then theres no clickable folder any more. I just have one problem now: I can visit the complete file system now, so I can also go out of var/www, so for example navigate to /etc, do you know how to avoid that?
– user5638730
Apr 15 '16 at 17:31












do you have any idea?
– user5638730
Apr 16 '16 at 8:40




do you have any idea?
– user5638730
Apr 16 '16 at 8:40












you can keep if condition if(substr($_POST['data'], 0, strlen("yourwebroot")) ==="yourwebroot") $dir =$_POST['data']; else $dir ="path/to/webroot";
– Naisa purushotham
Apr 16 '16 at 17:47




you can keep if condition if(substr($_POST['data'], 0, strlen("yourwebroot")) ==="yourwebroot") $dir =$_POST['data']; else $dir ="path/to/webroot";
– Naisa purushotham
Apr 16 '16 at 17:47












yeah, I thought about something like that as well, but then there is one problem: if somebody knows how to deal with html then it's no problem to go to another directory anyway because they can just press f12 in chrome for developer tools and then they simply change the content of data-key to the folder they want and they're in.... What to do know?
– user5638730
Apr 17 '16 at 5:26




yeah, I thought about something like that as well, but then there is one problem: if somebody knows how to deal with html then it's no problem to go to another directory anyway because they can just press f12 in chrome for developer tools and then they simply change the content of data-key to the folder they want and they're in.... What to do know?
– user5638730
Apr 17 '16 at 5:26












if they change data-key also not a problem, for that if condition will work like this, for example, your document root is "xyz", now you want allow only xyz/images folder. datakey always like this : images/folder1,images/folder2,images/file.jpg... if condition will check directory is starting with images or not , if yes then it will go to sub directory(images/folder1/folder5), other wise it will show only images folder. i hope it will helpful..
– Naisa purushotham
Apr 18 '16 at 5:05




if they change data-key also not a problem, for that if condition will work like this, for example, your document root is "xyz", now you want allow only xyz/images folder. datakey always like this : images/folder1,images/folder2,images/file.jpg... if condition will check directory is starting with images or not , if yes then it will go to sub directory(images/folder1/folder5), other wise it will show only images folder. i hope it will helpful..
– Naisa purushotham
Apr 18 '16 at 5:05













0














use scandir() php in built function. it will return particular files and dirname in that locatoin



 $dir = '/path/to/my/directory';
$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

//your code here




//This is one more example to get files recursively.

function dirToArray($dir)

$result = array();

$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (!in_array($value,array(".","..")))

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);

else

$result = $value;




return $result;






share|improve this answer




















  • but I see it right, that this only lists the files once, and when clicking on a folder, what hapens then? Or am I wrong?
    – user5638730
    Apr 15 '16 at 6:54










  • use ajax call and get sub folder list, display the result, if folder add some class, by using jquery click event raise ajax call
    – Naisa purushotham
    Apr 15 '16 at 6:57











  • Could you tell me how such an ajax call is working? Seldom worked with AJAX....
    – user5638730
    Apr 15 '16 at 7:32















0














use scandir() php in built function. it will return particular files and dirname in that locatoin



 $dir = '/path/to/my/directory';
$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

//your code here




//This is one more example to get files recursively.

function dirToArray($dir)

$result = array();

$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (!in_array($value,array(".","..")))

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);

else

$result = $value;




return $result;






share|improve this answer




















  • but I see it right, that this only lists the files once, and when clicking on a folder, what hapens then? Or am I wrong?
    – user5638730
    Apr 15 '16 at 6:54










  • use ajax call and get sub folder list, display the result, if folder add some class, by using jquery click event raise ajax call
    – Naisa purushotham
    Apr 15 '16 at 6:57











  • Could you tell me how such an ajax call is working? Seldom worked with AJAX....
    – user5638730
    Apr 15 '16 at 7:32













0












0








0






use scandir() php in built function. it will return particular files and dirname in that locatoin



 $dir = '/path/to/my/directory';
$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

//your code here




//This is one more example to get files recursively.

function dirToArray($dir)

$result = array();

$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (!in_array($value,array(".","..")))

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);

else

$result = $value;




return $result;






share|improve this answer












use scandir() php in built function. it will return particular files and dirname in that locatoin



 $dir = '/path/to/my/directory';
$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

//your code here




//This is one more example to get files recursively.

function dirToArray($dir)

$result = array();

$cdir = scandir($dir);
foreach ($cdir as $key => $value)

if (!in_array($value,array(".","..")))

if (is_dir($dir . DIRECTORY_SEPARATOR . $value))

$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);

else

$result = $value;




return $result;







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 15 '16 at 6:39









Naisa purushotham

749615




749615











  • but I see it right, that this only lists the files once, and when clicking on a folder, what hapens then? Or am I wrong?
    – user5638730
    Apr 15 '16 at 6:54










  • use ajax call and get sub folder list, display the result, if folder add some class, by using jquery click event raise ajax call
    – Naisa purushotham
    Apr 15 '16 at 6:57











  • Could you tell me how such an ajax call is working? Seldom worked with AJAX....
    – user5638730
    Apr 15 '16 at 7:32
















  • but I see it right, that this only lists the files once, and when clicking on a folder, what hapens then? Or am I wrong?
    – user5638730
    Apr 15 '16 at 6:54










  • use ajax call and get sub folder list, display the result, if folder add some class, by using jquery click event raise ajax call
    – Naisa purushotham
    Apr 15 '16 at 6:57











  • Could you tell me how such an ajax call is working? Seldom worked with AJAX....
    – user5638730
    Apr 15 '16 at 7:32















but I see it right, that this only lists the files once, and when clicking on a folder, what hapens then? Or am I wrong?
– user5638730
Apr 15 '16 at 6:54




but I see it right, that this only lists the files once, and when clicking on a folder, what hapens then? Or am I wrong?
– user5638730
Apr 15 '16 at 6:54












use ajax call and get sub folder list, display the result, if folder add some class, by using jquery click event raise ajax call
– Naisa purushotham
Apr 15 '16 at 6:57





use ajax call and get sub folder list, display the result, if folder add some class, by using jquery click event raise ajax call
– Naisa purushotham
Apr 15 '16 at 6:57













Could you tell me how such an ajax call is working? Seldom worked with AJAX....
– user5638730
Apr 15 '16 at 7:32




Could you tell me how such an ajax call is working? Seldom worked with AJAX....
– user5638730
Apr 15 '16 at 7:32

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36639699%2fnavigate-through-webdirectory-in-browser%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3