PHP新建文件并写入内容demo
//保存数据库连接信息到conn.php $fp=fopen(INSTALL_PATH.'/../conn/conn.php','w'); if (!$fp) { echo "sorry,try again!"; } $conn_config="<?php \n"; $conn_config.="header('Content-type: text/html; charset=UTF-8');\n"; $conn_config.='$conn='; $conn_config.="mysql_connect('$tc_server','$tc_user_name','$tc_user_pass');\n"; $conn_config.='$select='; $conn_config.="mysql_select_db('$tc_data_name',\$conn)or die('数据库连接失败:'.mysql_error());//连接服务器\n"; $conn_config.="mysql_query('set names utf8');"; $conn_config.="\n ?>"; $fw=fwrite($fp,$conn_config); echo "create file end .<br/>"; if ($fw) { echo "success add conn.php !<br/>"; }else{ echo "Error!"; } fclose($fp);
技术文档