if(isset($_POST['submit'])){
$title=$_POST['title'];
$content=$_POST['content'];
$addtime=time();
$sql="insert into news (title,content,addtime) values ('$title','$content','$addtime')";
$rs=$db->query($sql);
if($rs){
$time=date('ymd');
$tmp=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/'.$time.$title.'.'.html;
$fp=fopen($tmp,'w');
$tmpT=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/tmp.html';
$fpT=fopen($tmpT,'r');
$str=fread($fpT,filesize($tmpT));
$str=str_replace('{title}',$title,$str);
$str=str_replace('{content}',$content,$str);
fwrite($fp,$str);
fclose($fp);
fclose($fpT);
echo "OK";
}
}
//==================================
echo "
";
echo $_SERVER['DOCUMENT_ROOT'];
echo "
";
echo $_SERVER['PHP_SELF'];
echo "
";
echo date('ymd');
echo "
";
echo dirname($_SERVER['PHP_SELF']);
?>
require "comm.php";
if(isset($_POST['submit'])){
$title=$_POST['title'];
$content=$_POST['content'];
$addtime=time();
$sql="insert into news (title,content,addtime) values ('$title','$content','$addtime')";
$rs=$db->query($sql);
if($rs){
$time=date('ymd');
$tmp=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/'.$time.$title.'.'.html;
$fp=fopen($tmp,'w');
$tmpT=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/tmp.html';
$fpT=fopen($tmpT,'r');
$str=fread($fpT,filesize($tmpT));
$str=str_replace('{title}',$title,$str);
$str=str_replace('{content}',$content,$str);
fwrite($fp,$str);
fclose($fp);
fclose($fpT);
echo "OK";
}
}
//==================================
echo "
";
echo $_SERVER['DOCUMENT_ROOT'];
echo "
";
echo $_SERVER['PHP_SELF'];
echo "
";
echo date('ymd');
echo "
";
echo dirname($_SERVER['PHP_SELF']);
?>
[html] //tmp.html
{content}
摘自 chaojie2009的专栏