建表,其中有个字段$content,放图片
<html>
<head>
<title>增加数据</title>
<script>
<!--
function checkdata()
{
var sFlag=true;
if(document.form1.title.value=='')
{
document.form1.title.focus()
sFlag=false;
alert('请输入文章标题!')
return false;
}
if(document.form1.content.value=='')
{
document.form1.content.focus();
sFlag=false;
alert('文章内容为空,系统无法提交!请你输入文章内容!');
return false;
}
if(document.form1.imagein.value=='')
{
document.form1.imagein.focus();
sFlag=false;
alert('图片为空,系统无法提交!请你输入图片!');
return false;
}
return sFlag;
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" onLoad="document.form1.title.focus()">
<?
$query_cncoldb="select cnname from name where enname='$coldb'";
$result_cncoldb=mysql_query($query_cncoldb);
list($cncoldb)=mysql_fetch_row($result_cncoldb);
$query_cncoltb="select cnname from name where enname='$coltb'";
$result_cncoltb=mysql_query($query_cncoltb);
list($cncoltb)=mysql_fetch_row($result_cncoltb);
?>
<p align="left">当前栏目>><?echo $cncoldb;?>>><?echo $cncoltb;?> <p align="center"><font size="4">录入数据</font> </p>
<form name="form1" ENCTYPE="multipart/form-data" method="post" onSubmit="return checkdata()" action="adddata.php">
<div align="center">
<table width="75%" border="0">
<tr>
<td>文章标题:
<input type="text" name="title" size="40">
作者:
<input type="text" name="author">
</td>
</tr>
<tr>
<td>
<p align="left">文章内容:
<textarea name="content" cols="90" rows="10"></textarea>
</p>
</td>
</tr>
<tr>
<td>
<div align="left">出处:
<input type="text" name="origin" size="80">
</div>
</td>
</tr>
<tr>
<td>
<div align="left">图片:
<input type="file" name="imagein">
</div>
</td>
</tr>
<tr>
<td>
<div align="center"> </div>
</td>
</tr>
<tr>
<td>
<div align="center"><font size="4">
<input type="submit" name="submit" value="提交">
<input type="reset" value="清空" name="reset">
<input type="button" value="重新选择栏目" onClick="window.location.href='select.php'">
</font></div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<html>
<head>
<title>增加数据</title>
<script>
<!--
function checkdata()
{
var sFlag=true;
if(document.form1.title.value=='')
{
document.form1.title.focus()
sFlag=false;
alert('请输入文章标题!')
return false;
}
if(document.form1.content.value=='')
{
document.form1.content.focus();
sFlag=false;
alert('文章内容为空,系统无法提交!请你输入文章内容!');
return false;
}
if(document.form1.imagein.value=='')
{
document.form1.imagein.focus();
sFlag=false;
alert('图片为空,系统无法提交!请你输入图片!');
return false;
}
return sFlag;
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" onLoad="document.form1.title.focus()">
<?
$query_cncoldb="select cnname from name where enname='$coldb'";
$result_cncoldb=mysql_query($query_cncoldb);
list($cncoldb)=mysql_fetch_row($result_cncoldb);
$query_cncoltb="select cnname from name where enname='$coltb'";
$result_cncoltb=mysql_query($query_cncoltb);
list($cncoltb)=mysql_fetch_row($result_cncoltb);
?>
<p align="left">当前栏目>><?echo $cncoldb;?>>><?echo $cncoltb;?> <p align="center"><font size="4">录入数据</font> </p>
<form name="form1" ENCTYPE="multipart/form-data" method="post" onSubmit="return checkdata()" action="adddata.php">
<div align="center">
<table width="75%" border="0">
<tr>
<td>文章标题:
<input type="text" name="title" size="40">
作者:
<input type="text" name="author">
</td>
</tr>
<tr>
<td>
<p align="left">文章内容:
<textarea name="content" cols="90" rows="10"></textarea>
</p>
</td>
</tr>
<tr>
<td>
<div align="left">出处:
<input type="text" name="origin" size="80">
</div>
</td>
</tr>
<tr>
<td>
<div align="left">图片:
<input type="file" name="imagein">
</div>
</td>
</tr>
<tr>
<td>
<div align="center"> </div>
</td>
</tr>
<tr>
<td>
<div align="center"><font size="4">
<input type="submit" name="submit" value="提交">
<input type="reset" value="清空" name="reset">
<input type="button" value="重新选择栏目" onClick="window.location.href='select.php'">
</font></div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
adddata.php
<?
if($username)
{
@$link=mysql_pconnect("localhost","user","password") or die ("登陆服务器失败,请稍候再试");
mysql_select_db("database");
$query="select $tablename from user where uname='$username'";
$result=mysql_query($query,$link);
list($coldb)=mysql_fetch_row($result);
mysql_select_db("$coldb");
$date=date('Y-m-d H:i:s');
if($coldb=="foljrbd"&&$coltb=="tpxw“
{
if(chop($imagein)!="none")
{
$picuppath="/xxxxxxx/"; //define up pic path
$dirname="picup";
if(!(chdir($picuppath)))
{
die("can not change path!");
}
if(!(file_exists("$dirname")))
{
if(!(mkdir($dirname,0777))) die("can not make dir!");
if(!(chmod($dirname,0777))) die("can not change dir mode!");
}
if(!(chdir($dirname))) die("can not change dir!");
$dirpath=$dirname."/";
$imagepath=$picuppath.$dirpath; //path end $image="";
$imagename="";
$imagetype="";
$nowtime=time(); $imagename=$imagein_name ; //old pic name for db
$imagetail=strrchr($imagename,"."); //get pic name type name
$imagename=$nowtime.$imagetail;
if(!copy($imagein,$imagepath.$imagename)) die("up pic false"); //up pic end
$size=getimagesize($imagename); //get size array,for now in uppic,so just imagename else dirpaht
$imgwidth=$size[0];
$imgheight=$size[1];
$imgsize=$size[3];
unlink($imagename); //delete pic in remote $image=base64_encode(fread(fopen($imagein,"r"),10000000)); //inset db begin
$imagetype=$imagein_type ;
$imgtype=$imagetype;
unlink($imagein); $imgoldname=$imagename;
$imgname=$imagename;
$imgbody=$image;
if($coldb=="foljrbd"&&coltb=="tpxw"){//there is no summary in tpxw of foljrbd,so ...
$result =mysql_query("insert into $coltb (title,content,date,author,origin,imgoldname,imgtype,imgname,imgwidth,imgheight,imgsize,imgbody) values('$title','$content','$date','$author','$origin','$imgoldname','$imgtype','$imgname','$imgwidth','$imgheight','$imgsize','$imgbody')",$link);
}
else{//tpxw of foljrbd
$result =mysql_query("insert into $coltb (title,summary,content,date,author,origin,imgoldname,imgtype,imgname,imgwidth,imgheight,imgsize,imgbody) values('$title','$summary','$content','$date','$author','$origin','$imgoldname','$imgtype','$imgname','$imgwidth','$imgheight','$imgsize','$imgbody')",$link);
}
}
else die("请上传图片");
}//end of pic or pic with no summary
elseif($coldb=="foljrbd"&&$coltb=="cjzt"){//beggin of cjzt of fol jrbd
$result =mysql_query("insert into $coltb (title,content,date,author,origin,topic) values('$title','$content','$date','$author','$origin','$topic')",$link);
}//end of cjzt of fol jrbd
elseif($col=="foljrsx"&&$coltb=="pshzl")//for jrsxdb==
{
if(chop($imagein)!="none")
{
$picuppath='/home/fol/jrsx/'; //define up pic path
$dirname="article";
if(!(chdir($picuppath) ))
{
die("can not change path!");
}
if(!(file_exists("$dirname")))
{
if(!(mkdir($dirname,0777))) die("can not make dir!");
if(!(chmod($dirname,0777))) die("can not change dir mode!");
}
if(!(chdir($dirname))) die("can not change dir!");
$dirpath=$dirname."/";
$imagepath=$picuppath.$dirpath; //path end $image="";
$imagename="";
$imagetype="";
$nowtime=time(); $imagename=$imagein_name ; //old pic name for db
$imagetail=strrchr($imagename,"."); //get pic name type name
$imagename=$nowtime.$imagetail;
if(!copy($imagein,$imagepath.$imagename)) die("up pic false"); //up pic end
//unlink($imagename); //delete pic in remote //$image=base64_encode(fread(fopen($imagein,"r"),10000000)); //inset db begin
$imagetype=$imagein_type ;
$imgtype=$imagetype;
unlink($imagein); $imgoldname=$imagename;
$imgname=$imagename;
$imgbody=$image;
$result =mysql_query("insert into $coltb (title,content,date,author,origin,artcloldname,artcltype,artclname) values('$title','$content','$date','$author','$origin','$imgoldname','$imgtype','$imgname')",$link);
}