开发者

Display directory structure to admin

i am developing a CMS in which i hav to show the administrator the directory structue开发者_运维百科 of root folder. What im doing is getting the directory structure using php and trying to print it on the client web page using javascript (echo"<script>javaFunc()</script>") , now after visiting different forums, i see people are saying that its not a gud idea to call javascript from php!! is it so? if yes then wats shud be the proper way for displaying the server directory structure, at client side?


Would be a good idea to echo back the array of directory names as a JSON array, so compile your array in PHP then json_encode() it in PHP.

$directories = array('file1', 'file2');
echo json_encode($directories);

Then get the data using AJAX at the client side and format it how you want. (jquery example)

$.ajax({
    url: 'ajax.php',
    success: function(return_data)
    {
        // return_data has your directories
    }
});

Be very careful you don't allow people to trick the server into listing ie. the root folder or worse by using functions realpath() and basename() and proper validation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜