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);
相關文章
相關標籤/搜索