file_append
This commit is contained in:
parent
5f3ae65b17
commit
dd14dbb6e3
Binary file not shown.
@ -3,6 +3,7 @@ System Functions
|
||||
basename
|
||||
dirname
|
||||
expand_path
|
||||
file_append
|
||||
file_exists
|
||||
file_get_contents
|
||||
file_mtime
|
||||
@ -10,6 +11,7 @@ file_put_contents
|
||||
get_cwd
|
||||
ls
|
||||
mkdir
|
||||
print
|
||||
set_cwd
|
||||
shell_escape
|
||||
shell_exec
|
||||
|
||||
12
doc/pages/file_append.txt
Normal file
12
doc/pages/file_append.txt
Normal file
@ -0,0 +1,12 @@
|
||||
:sig
|
||||
void file_append(String file_name, ...val)
|
||||
|
||||
:params
|
||||
file_name : file name of file that should be written to
|
||||
...val : one or more values that should be written into the file
|
||||
|
||||
:desc
|
||||
Opens or creates a given file and appends data to it.
|
||||
|
||||
:see
|
||||
>sys
|
||||
11
doc/pages/print.txt
Normal file
11
doc/pages/print.txt
Normal file
@ -0,0 +1,11 @@
|
||||
:sig
|
||||
void print(...val)
|
||||
|
||||
:params
|
||||
...val : one or more values that should be output
|
||||
|
||||
:desc
|
||||
Appends data to the current request's output stream.
|
||||
|
||||
:see
|
||||
>sys
|
||||
@ -8,6 +8,16 @@ bool mkdir(String path);
|
||||
bool file_exists(String path);
|
||||
String file_get_contents(String file_name);
|
||||
bool file_put_contents(String file_name, String content);
|
||||
#include <fstream>
|
||||
template <typename... Ts>
|
||||
bool file_append(String file_name, Ts... args)
|
||||
{
|
||||
std::ofstream fout;
|
||||
fout.open(file_name.c_str(), std::ios_base::app);
|
||||
((fout << args), ...);
|
||||
fout.close();
|
||||
return(true);
|
||||
}
|
||||
String get_cwd();
|
||||
void set_cwd(String path);
|
||||
time_t file_mtime(String file_name);
|
||||
|
||||
36
test/file_append.uce
Normal file
36
test/file_append.uce
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
|
||||
|
||||
RENDER()
|
||||
{
|
||||
DTree t;
|
||||
|
||||
<>
|
||||
<link rel="stylesheet" href='style.css'></link>
|
||||
<h1>
|
||||
<a href="index.uce">UCE Test</a>:
|
||||
File Append
|
||||
</h1>
|
||||
|
||||
File Append:
|
||||
|
||||
<pre style="white-space: pre-wrap"><?
|
||||
|
||||
if(context->get["cmd"] == "clear")
|
||||
file_put_contents("/tmp/test.txt", "");
|
||||
|
||||
file_append("/tmp/test.txt", context->server->request_count, "\thello world\t", 2, "\t", time(), "\t", microtime(), "\n");
|
||||
|
||||
print(file_get_contents("/tmp/test.txt"));
|
||||
|
||||
?></pre>
|
||||
|
||||
<button onclick="document.location.href='?cmd=add';">Add Line</button>
|
||||
<button onclick="document.location.href='?cmd=clear';">Clear File</button>
|
||||
|
||||
Params
|
||||
<pre><?= var_dump(context->params) ?></pre>
|
||||
</>
|
||||
|
||||
}
|
||||
@ -25,6 +25,7 @@ RENDER()
|
||||
<li><a href="memcached.uce">Memcached</a></li>
|
||||
<li><a href="mysql.uce">MySQL Connector</a></li>
|
||||
<li><a href="fileio.uce">File I/O</a></li>
|
||||
<li><a href="file_append.uce">File Append</a></li>
|
||||
<li><a href="random.uce">RNG/Noise</a></li>
|
||||
<li><a href="task.uce">Task API</a></li>
|
||||
</ul>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user