我正在尝试创建一个添加用户的php文件,并使用exec()function(php)在linux中创建public_html目录。
我可以将以下代码添加到php文件中
exec(“useradd -d/home/username -m username”);
exec(“mkdir/home/username/public_html”);
现在,我必须在smb.conf中添加public_html才能在Windows上工作public_html。
是否可以在命令行上编辑smb.conf?
当然,我将使用SSH作为根目录来执行php文件。
最佳答案
看一看parse_ini_file()函数。
然后,如果您想在ini文件中编写,请尝试以下操作:
function writeini($file,$title,$item,$data) {
$source = file($file);
$t_match = "/^\[".$title."\]/i";
$s_title = "";
$c = "0";
$o = "";
foreach ($source as $temp) {
$c++;
if (preg_match("/^\[.+\]/i",$temp)) {
if (preg_match($t_match,$l_title)) {
$done = "yes";
$f_write .= $item."=".$data."\n";
}
$l_title = $temp;
$f_write .= $temp;
} elseif (preg_match("/^".$item."=/i",$temp) && preg_match($t_match,$l_title)) {
$done = "yes";
$f_write .= $item."=".$data."\n";
$l_title = "";
} elseif ($c == count($source) && $done != "yes") {
if (preg_match($t_match,$l_title)) {
$f_write .= $temp.$item."=".$data."\n";
} else {
$f_write .= $temp."[".$title."]\n".$item."=".$data."\n";
}
} else {
$f_write .= $temp;
}
}
$ini_write = fopen($file,'w');
fwrite($ini_write,$f_write);
fclose($ini_write);
}
关于php - 如何在命令行上编辑文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/928743/