示例:我有这个文件名更改日志 2013.txt但是当它是 2014 年时,我希望它创建新的文件名更改日志 2014.txt
任何人都可以帮忙吗?这是我的控制器:
<?php
class changelog extends Controller {
function changelog()
{
parent::Controller();
$this->load->helper('form');
}
function index()
{
$this->change_log_add();
}
function change_log_view()
{
$data['message'] = read_file('C:\wamp\www\changeLog\change log 2013.txt');
$this->load->view('change_log_view', $data);
}
function change_log_add()
{
$this->session->set_flashdata('msg','Please Insert the task changed');
$data['action'] = 'changelog/change_log_save_add/';
$this->load->view('change_log_form', $data);
}
function change_log_save_add()
{
if($this->input->post('message') != NULL)
{
date_default_timezone_set ("Asia/Singapore");
$data = date("Y-m-d, H:i:s");
$body = $this->input->post('message');
$text = $data.' - '.$body."\r\n";
if ( ! write_file('C:\wamp\www\changeLog\change log 2013.txt', $text, 'a+'))
{
echo 'Unable to write the file';
}
else
{
$this->session->set_flashdata('msg', 'File Written');
redirect('changelog/change_log_read/');
}
}
}
function change_log_read()
{
if(read_file('C:\wamp\www\changeLog\change log 2013.txt') == NULL)
{
echo 'File is Empty!';
}
else
{
$string = read_file('C:\wamp\www\changeLog\change log 2013.txt');
echo $string;
redirect('changelog/change_log_view/');
}
}
function change_log_update()
{
$this->session->set_flashdata('msg','Please Insert the task changed');
$data['message'] = read_file('C:\wamp\www\changeLog\change log 2013.txt');
$data['action'] = 'changelog/change_log_save_update/';
$this->load->view('change_log_form', $data);
}
function change_log_save_update()
{
if($this->input->post('message') != NULL)
{
$message = $this->input->post('message');
if ( ! write_file('C:\wamp\www\changeLog\change log 2013.txt', $message, 'r+'))
{
echo 'Unable to write the file';
}
else
{
$this->session->set_flashdata('msg', 'File Written');
redirect('changelog/change_log_read/');
}
}
}
}