PHP写文件函数

/**
 * 写文件函数
 *
 * @param string $filename 文件名
 * @param string $text 要写入的文本字符串
 * @param string $openmod 文本写入模式('w':覆盖重写,'a':文本追加)
 * @return boolean
 */
function write_file($filename, $text, $openmod = 'w') {
	if (@$fp = fopen($filename, $openmod)) {
		flock($fp, 2);
		fwrite($fp, $text);
		fclose($fp);
		return true;
	} else {
		return false;
	}
}

延伸阅读:

PHP判断文件或者目录是否可写

原文地址:https://www.cnblogs.com/52php/p/5687403.html