douzuanze0486 2015-02-04 15:52
浏览 26

如何在PHP中的文本文件中编辑不同用户的特定行

I have a Subversion server running with AuthzSVNAccessFile specified in a virtual host. The file "permissions.txt" should be edited by the users themselves to add or remove team members but limited to max. 4 members. Possible via PHP and how to implement it? In PHP each logged in user has the $username = user_x; whereas x is an integer.

The AuthzSVNAccessFile "permissions.txt":

[repo_1001:/]
user_1 = rw
# the lines below only editable by user_1
user_1-member_1 = r
user_1-member_2 = r
user_1-member_3 = r
user_1-member_4 = r

[repo_1002:/]
user_2 = rw
# the lines below only editable by user_2
user_2-member_1 = rw
user_2-member_2 = rw

Reading and writing the file in PHP:

$file_permissions = "/.../permissions.txt";

if (isset($_POST) && ...) {
    $textFileContents = $_POST['textFileContents'];
    $fd=fopen($file_permissions ,"w");
    fwrite($fd, $textFileContents);
    fclose($fd);
}

$fd = fopen($file_permissions,"r");
$textFileContents = fread($fd,filesize($file_permissions));
fclose($fd);

var_dump($textFileContents);

I tried "AbraCadaver" mentioned parse-ini-file function but I do not get any output.
Even no errors are seen:

$file_permissions = "/.../permissions.txt";

$textFileContents = parse_ini_file($file_permissions);

var_dump($textFileContents);

The output is just "NULL".

ADD: The cause why I got "NULL" is that my php.ini on the remote server was configured to disable the function parse_ini_file for security reasons.
Now it works!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 touchsocket udp组播
    • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
    • ¥15 VS2012中查询语句无法填入解析,数值传不进去
    • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错
    • ¥15 怎么让ai定时给我发信息 c#或者python
    • ¥15 scrapy的Error
    • ¥15 RBF-VSG姚凤军论文复现问题
    • ¥30 开发一个APP商城在制作tabbar的时候运行不了代码没有检查出错误,但是显示不出tabbar,以下为运行结果,如何解决?
    • ¥15 多网卡服务器中winform如何绑定指定网卡
    • ¥15 关于#python#pandas#的问题,想要实现:多个TXT导入Excel,进行分列,不同txt之间都从第一行开始,请各位专家解答!