我正在使用CodeIgniter上传.ini
文件。
上传文件后,我使用PHP的INI解析器并将文件内容作为数组获取。
现在我想编辑该文件的内容。我该怎么做?
我的代码:
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('customer/upload/upload_ini', $error);
}
else
{
$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);
$this->data['subview'] = 'customer/upload/upload_success';
$this->load->view('customer/_layout_main', $this->data);
}
}
在视图中我做:
<?php
var_dump($parameters);
?>
<tr>
<td>OTAID</td>
<td><?php echo form_input('OTAID', set_value('OTAID', $parameters->OTAID)); ?></td>
</tr>
<tr>
<td>SipUserName</td>
<td><?php echo form_input('SipUserName', set_value('SipUserName', $parameters->SipUserName)); ?></td>
</tr>
<tr>
<td>SipAuthName</td>
<td><?php echo form_input('email2', set_value('email2', $parameters->email2)); ?></td>
</tr>
<tr>
<td>DisplayName</td>
<td><?php echo form_input('email2', set_value('email2', $parameters->email2)); ?></td>
</tr>
<tr>
<td>Password</td>
<td><?php echo form_input('email2', set_value('email2', $parameters->email2)); ?></td>
</tr>
<tr>
<td>Password</td>
<td><?php echo form_input('email2', set_value('email2', $parameters->email2)); ?></td>
</tr>
<tr>
<td>Domain</td>
<td><?php echo form_input('email2', set_value('email2', $parameters->email2)); ?></td>
</tr>
<tr>
<td>Proxy</td>
<td><?php echo form_input('email2', set_value('email2', $parameters->email2)); ?></td>
</tr>
<tr>
<td>ServerMode</td>
<td><?php echo form_input('email2', set_value('email2', $parameters->email2)); ?></td>
</tr>
从我的文件中我得到了这个内容:
array (size=9)
'OTAD' => string '0' (length=1)
'PName' => string '' (length=0)
'UName' => string '' (length=0)
'DisplayName' => string '' (length=0)
'Password' => string '' (length=0)
'Domain' => string '' (length=0)
'Proxy' => string '' (length=0)
'Port' => string '' (length=0)
'ServerMode' => string 'Automatic' (length=9)
答案 0 :(得分:1)
使用此编码
<td>OTAID</td>
<td><?php echo form_input('OTAID', set_value('OTAID', $parameters->OTAID)); ?></td>
</tr>
<tr>
<td>SipUserName</td>
<td><?php echo form_input('SipUserName', set_value('SipUserName', $parameters['SipUserName'])); ?></td>
</tr>
<tr>
<td>SipAuthName</td>
<td><?php echo form_input('email2', set_value('email2', $parameters['email2'])); ?></td>
</tr>
<tr>
<td>DisplayName</td>
<td><?php echo form_input('email2', set_value('email2', $parameters['email2'])); ?></td>
</tr>
<tr>
<td>Password</td>
<td><?php echo form_input('email2', set_value('email2', $parameters['email2'])); ?></td>
</tr>
<tr>
<td>Password</td>
<td><?php echo form_input('email2', set_value('email2', $parameters['email2'])); ?></td>
</tr>
<tr>
<td>Domain</td>
<td><?php echo form_input('email2', set_value('email2', $parameters['email2'])); ?></td>
</tr>
<tr>
<td>Proxy</td>
<td><?php echo form_input('email2', set_value('email2', $parameter['email2'])); ?></td>
</tr>
<tr>
<td>ServerMode</td>
<td><?php echo form_input('email2', set_value('email2', $parameters['email2'])); ?></td>
</tr>
答案 1 :(得分:0)
如评论中所述,您需要在视图中使用 $ parameters 作为数组,因为 parse_ini_file 会返回一个。
您想要生成哪种文本框?您使用的是普通输入字段,是指 textarea ?
如何从数组生成ini文件,您可以看到here。您可以使用 file_put_contents 写入文件。