【发布时间】:2016-02-22 13:21:34
【问题描述】:
您好我想将一个ini文件写入php。 首先我将一个ini文件上传到我的服务器然后我编辑它, 我想对参数进行一些更改,然后将该文件保存回上传。
我使用了put_file_contents 和fwrite,但没有得到所需的结果。
这是我的代码:
$data = array('upload_data' => $this->upload->data());
foreach ($data as $info)
{
$filepath = $info['file_path'];
$filename= $info['file_name'];
}
$this->data['parameters'] = parse_ini_file($filepath.$filename);
$insert = array(
'OTAID' => $this->input->post('OTAID'),
'SipUserName' => $this->input->post('SipUserName') ,
'SipAuthName' => $this->input->post('SipAuthName'),
'DisplayName' => $this->input->post('DisplayName'),
'Password' => $this->input->post('Password'),
'Domain' => $this->input->post('Domain'),
'Proxy' => $this->input->post('Proxy'),
'ServerMode' => $this->input->post('ServerMode')
);
$this->load->helper('file');
$file =fopen($filepath.$filename,'w');
fwrite($file,implode('', $insert));
$this->data['subview'] = 'customer/upload/upload_success';
$this->load->view('customer/_layout_main', $this->data);
【问题讨论】:
-
implode不写关联数组的键。因此,如果您需要 INI 中的那些,这将不起作用。 -
你应该使用 array_keys($insert) 来获取 $insert 数组的键。
-
@apokryfos 那我该怎么办?我有一个数组,我想以 ini 格式编写该数组
-
这将如何帮助编写 .ini 文件? @RaviHirani
-
@Rajan :我告诉过你从数组中获取密钥。我不确定 .ini 文件是否写入。我需要为此制作演示。如果我发现了什么,我会发布它。
标签: php codeigniter