好的,所以我有 filezilla 服务器软件设置,但我想要一个 php 脚本,它将一个新用户添加到包含用户名、密码和文件夹的 xml 文件中。我希望它将其添加到现有的 xml 文件中,而不删除其中的当前信息。如果您知道执行此操作的可用方法或脚本,请将其发送给我或分享您的知识。否则,如果有另一个 ftp 服务器程序为每个用户提供单独的 xml 或文件,请告诉我。在此先感谢,马特。
问问题
4265 次
2 回答
2
最好的办法是使用SimpleXML来操作 XML 文件。
- 使用simplexml_load_file打开文件。确保您对该文件具有读/写权限。
- 使用SimpleXMLElement类添加和删除节点。
于 2012-04-16T03:46:53.990 回答
1
$user = $xml->Users->addChild('User');
$user->addAttribute('Name', $user_name);
add_option($user,'Pass',md5($password));
add_option($user,'Group',null);
add_option($user,'Bypass server userlimit','0');
add_option($user,'User Limit','0');
add_option($user,'IP Limit','0');
add_option($user,'Enabled','1');
add_option($user,'Comments','none');
add_option($user,'ForceSsl','0');
$filter = $user->addChild('IpFilter');
$filter->addChild('Disallowed');
$filter->addChild('Allowed');
$permissions = $user->addChild('Permissions');
$permission = $permissions->addChild('Permission');
$permission->addAttribute('Dir', str_replace("/","\\",$ftpUserFolder));
add_option($permission,'FileRead','1');
add_option($permission,'FileWrite','1');
add_option($permission,'FileDelete','1');
add_option($permission,'FileAppend','1');
add_option($permission,'DirCreate','1');
add_option($permission,'DirDelete','1');
add_option($permission,'DirList','1');
add_option($permission,'DirSubdirs','1');
add_option($permission,'IsHome','1');
add_option($permission,'AutoCreate','1');
$speed = $user->addChild('SpeedLimits');
$speed->addAttribute('DlType', '1');
$speed->addAttribute('DlLimit', '10');
$speed->addAttribute('ServerDlLimitBypass', '0');
$speed->addAttribute('UlType', '1');
$speed->addAttribute('UlLimit', '10');
$speed->addAttribute('ServerUlLimitBypass', '0');
$speed->addChild('Download');
$speed->addChild('Upload');
if(!$rv = $xml->asXML($xmlfile)){
echo ('SimpleXML could not write file');
return false;
}
//Change file encoding from UTF8 to ISO-8859-1
$dom = new DOMDocument("1.0","ISO-8859-1");
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
if(!$dom->load($xmlfile) || !$dom->save($xmlfile)){
echo ('DOMDocument could not change file enconding from UTF8 to ISO-8859-1');
我博客中的完整脚本:http://moshez.blogspot.co.il/2013/02/php-filezilla-ftp-server-auto-create.html
于 2013-03-18T17:29:27.997 回答