12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace app\common\model\base\models;
- /**
- * @title : 文件处理
- * @desc :
- * @Author : Rock
- * @Date : 2023-04-18 09:44:11
- */
- class FileServer
- {
- /**
- * @title: 追加单行文本至文件尾
- * @desc: 描述
- * @param {string} {filename} {} {文件名}
- * @param {string} {content} {} {追加的文本内容}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-18 09:58:40
- */
- static public function appendLine(string $filename, string $content='')
- {
- $fp = fopen($filename,'a');
- fwrite($fp,$content);
- fclose($fp);
- }
- /**
- * @title: 追加多行文本至文件末尾
- * @desc: 描述
- * @param {array} {filename} {} {文件名}
- * @param {array} {content} {} {待追加的文本数组}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-18 09:58:52
- */
- static public function appendAll(string $filename,array $content=[])
- {
- $fp = fopen($filename,'a');
- foreach($content as $item){
- fwrite($fp,$item);
- }
- fclose($fp);
- }
- /**
- * @title: 从文件头写入单行文本
- * @desc: 描述
- * @param {string} {filename} {} {文件名}
- * @param {string} {content} {} {文本内容}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-18 10:14:18
- */
- static public function writeLine(string $filename,string $content='')
- {
- $fp = fopen($filename,'w');
- fwrite($fp,$content);
- fclose($fp);
- }
- /**
- * @title: 从文件头写入多行文本
- * @desc: 描述
- * @param {string} {filename} {} {文件名}
- * @param {array} {content} {} {文本内容数组}
- * @return {*}
- * @author: Rock
- * @method: POST
- * @Date: 2023-04-18 10:15:06
- */
- static public function writeAll(string $filename,array $content=[])
- {
- $fp = fopen($filename,'w');
- foreach($content as $item){
- fwrite($fp,$item);
- }
- fclose($fp);
- }
- }
|