Roman
Roman

Reputation: 83

read samba config file in PHP

Can please somebody help me i want show on my server page samba shered folder and his patch. I try something like this i found this on web but can't show path. thanks for every respons and sorry for my english.

    <?php
$smb = file('smb.conf');

        foreach ($smb as $line) {
        $trim_line = trim ($line);
        $begin_char = substr($trim_line, 0, 1);
        $end_char = substr($trim_line, -1);
            if (($begin_char == "#") || ($begin_char == ";" || $trim_line == "[global]")) { } 
             elseif (($begin_char == "[") && ($end_char == "]")) { 
        $section_name = substr ($trim_line, 1, -1);
                echo $section_name . '<br>';
                }

//elseif ($trim_line != "") { 
//$pieces = explode("=", $trim_line , 1); 
//echo $pieces[0]. "<br>";
}
?>

Upvotes: 0

Views: 551

Answers (1)

Axel Amthor
Axel Amthor

Reputation: 11096

Try the php function parse_ini_file which will do the parsing and puts everything in handy arrays.

Then you are able to access the path section of any share with something like

  $sambaConfigArray = parse_ini_file ( <your samba file path>, true );
   .... $sambaConfigArray['sharename']['path'];

Upvotes: 2

Related Questions