';$handle = fopen("D:/wamp/www/liuyanban.html","a"); fseek($handle, -140,SEEK_END); fwrite($handle, "ok"); fclose($handle);?>
I want to ask why I have used fseek to change the file pointer to the last 140 bytes, but when written, or written at the end of the file, if this is wrong, why? What is the rational idea?
Reply content:
';$handle = fopen("D:/wamp/www/liuyanban.html","a"); fseek($handle, -140,SEEK_END); fwrite($handle, "ok"); fclose($handle);?>
I want to ask why I have used fseek to change the file pointer to the last 140 bytes, but when written, or written at the end of the file, if this is wrong, why? What is the rational idea?
The file is opened in a way that is used r+
.
http://php.net/manual/zh/function.fopen.php
'r' 只读方式打开,将文件指针指向文件头。'r+' 读写方式打开,将文件指针指向文件头。'w' 写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。'w+' 读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。'a' 写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。'a+' 读写方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建之。
About fseek
Some of the cases.
http://php.net/manual/zh/function.fseek.php
Note:如果使用附加模试(a 或 a+),任何写入文件数据都会被附加上去,而文件的位置将会被忽略,调用 fseek() 的结果尚未定义。
The resulting effect is to write the specified character at the specified position without reaching the insertion effect.
To achieve the effect of the insert, you need to jump to the specified location, get everything behind it, then write what you want to write, and then write the original content.