The project is THINKPHP5, the backstage has one, uploads the HTML template code the function.
Because in the template, in addition to the HTML code, there are,
{volist name= "list" id= "Vo"} {/volist} {$title}
Php,js code.
I did it by first building a template table.
CREATE TABLE hk_template (id INT () PRIMARY KEY not NULL, name VARCHAR (+), content TEXT COMMENT ' markdown code ', content_html TEXT COMMENT ' HTML code ', filepath VARCHAR (255) COMMENT ' Where, for example: application/index/view/special/detail.html ', Status TINYINT (1) DEFAULT ' 1 ' COMMENT ' 1 enabled, 0 not enabled ', Create_time Int (ten), Update_time Int (ten), Create_uid Int ( ), Update_uid INT (10));
Write, use the TextArea box, and write all of the code into the content.
After the write succeeds, the content,
Placed in the template file.
Because there is a definition of app_path in/public/index.php,
[Application Portal File]//defines the application directory define (' App_path ', __dir__. ‘/.. /application/');d efine (' web_url ', ' http://'. $_server[' Http_host ']);//load frame boot file require __dir__. ‘/.. /thinkphp/start.php ';
The. Edit method is as follows:
Public function edit ($id) { $template = model (' template '); if (is_post) { $data = $_POST; // submit a form $result = $template->allowfield (True)->save ($data, [' id ' = + $data [' id ']]); if ($result) { // target file: application/index/view/special/detail.html, replace the content inside. // $filename = app_path. ' Index/view/specail/detail.html '; // chmod ($filename, 777); //write this sentence without permission to modify, you have to manually modify the directory under the      &Nbsp; $file = fopen ($filename, "w") //Open file in write mode fwrite ($file, $data [' content ']; / /write First line fclose ($file); //Close file return $this->success ("updated successfully! ", url (' Admin/template/index ')); } else { return $this->error ($template GetError (), url (' Admin/template/add ')); } }else{ // Records if (! $id) { $this Error (' illegal operation '); } $info = $template- >where (' id ', $id)->find (); if (! $info) { return $this->error ($template->geterror ()); } $this Assign (' info ', $info); $this->setmeta (' template editing '); return $this->fetch (); }}
The following is reproduced from:
Http://www.jb51.net/article/68202.htm
This example describes how PHP writes, deletes, and copies files. Share to everyone for your reference. Specific as follows:
Write:
<?php
$filename
=
"Test//file.txt"
;
$file
=
fopen
(
$filename
,
"w"
);
//以写模式打开文件
fwrite(
$file
,
"Hello, world!/n"
);
//写入第一行
fwrite(
$file
,
"This is a test!/n"
);
//写入第二行
fclose(
$file
);
//关闭文件
?>
2. Delete:
<?php
$filename
=
"Test//file.txt"
;
unlink(
$filename
);
//删除文件
?>
3. Copy:
<?php
$filename1
=
"Test//file.txt"
;
$filename2
=
"Test//file.bak"
;
copy
(
$filename1
,
$filename2
);
//复制文件
?>
I hope this article is helpful to everyone's PHP programming.
Update of template file HTML in TP5 project and methods of PHP writing, deleting and copying files