add.php文件,提交的图片,文字用adddata.php文件来处理
<html>
<head>
<title>增加数据</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#FFFFFF">
<?
if($db=="foljrbd"&&$tb=="cjzt"){
?>
<form name="form1" method="post" action="addcjzt.php" enctype="multipart/form-data">
<table width="50%" border="0" align="center">
<tr>
<td align="center">
<p>请选择需要增加内容的专题:</p>
<p> </p>
</td>
</tr>
<tr>
<td align="center">金融报道>>财经专题>>
<select name="topic">
<? @$link=mysql_pconnect("localhost","root","rpass007")
or die("登陆失败,稍后重试");
mysql_select_db("fol") or die("unable to select database");
$query="select topic,tpcname from foljrbd_cjzt order by id desc";
$result=mysql_query($query,$link);
while (list($topic,$tpcname)=mysql_fetch_row($result))
{
?>
<option value="<? echo $topic ?>">
<? echo $tpcname ?>
</option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<td align="right">
<input type="hidden" name="db" value="<? echo $db ?>">
<input type="hidden" name="tb" value="<? echo $tb ?>">
<input type="submit" name="Submit" value="填加">
</td>
</tr>
<tr>
<td>
<p> </p>
<p><a href="mkspecial.php?db=<? echo $db ?>&tb=<? echo $tb ?>">建立新的专题</a></p>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
<?
}elseif($db=="foljrsx"&&$tb=="pshzl")//beggin of pshzl of foljrsx
{
?>
<p align="center"><font size="4">论文上传</font> </p>
<form name="form1" ENCTYPE="multipart/form-data" method="post" action="adddata.php?db=<? echo $db ?>&tb=<? echo $tb ?>">
<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="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">
</font></div>
</td>
</tr>
</table>
</div>
</form>
<?
}//end of pshzl of foljrsxelse
{
?>
<p align="center"><font size="4">录入数据</font> </p>
<form name="form1" ENCTYPE="multipart/form-data" method="post" action="adddata.php?db=<? echo $db ?>&tb=<? echo $tb ?>">
<div align="center">
<table width="75%" border="0">
<tr>
<td>文章标题:
<input type="text" name="title" size="40">
作者:
<input type="text" name="author">
</td>
</tr>
<? if((($db=="foltyx"&&$tb=="wlg_master")||($db=="foljrsx"&&$tb=="pshzl"))||($db=="foljrxt"&&($tb!="hbyh"&&$tb!="tzlc")))
{
?>
<tr>
<td>
<p align="left">简短介绍:
<textarea name="summary" cols="80" rows="3"></textarea>
</p>
</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>
<? if((($db=="foltyx"&&$tb=="wlg_master")||($db=="foljrbd"&&$tb=="tpxw"))||($db=="foljrxt"&&($tb=="shpx"||$tb=="tswl")))
{
?>
<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">
</font></div>
</td>
</tr>
</table>
</div>
</form>
<?
}
?>
</body>
</html>
<html>
<head>
<title>增加数据</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#FFFFFF">
<?
if($db=="foljrbd"&&$tb=="cjzt"){
?>
<form name="form1" method="post" action="addcjzt.php" enctype="multipart/form-data">
<table width="50%" border="0" align="center">
<tr>
<td align="center">
<p>请选择需要增加内容的专题:</p>
<p> </p>
</td>
</tr>
<tr>
<td align="center">金融报道>>财经专题>>
<select name="topic">
<? @$link=mysql_pconnect("localhost","root","rpass007")
or die("登陆失败,稍后重试");
mysql_select_db("fol") or die("unable to select database");
$query="select topic,tpcname from foljrbd_cjzt order by id desc";
$result=mysql_query($query,$link);
while (list($topic,$tpcname)=mysql_fetch_row($result))
{
?>
<option value="<? echo $topic ?>">
<? echo $tpcname ?>
</option>
<?
}
?>
</select>
</td>
</tr>
<tr>
<td align="right">
<input type="hidden" name="db" value="<? echo $db ?>">
<input type="hidden" name="tb" value="<? echo $tb ?>">
<input type="submit" name="Submit" value="填加">
</td>
</tr>
<tr>
<td>
<p> </p>
<p><a href="mkspecial.php?db=<? echo $db ?>&tb=<? echo $tb ?>">建立新的专题</a></p>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
<?
}elseif($db=="foljrsx"&&$tb=="pshzl")//beggin of pshzl of foljrsx
{
?>
<p align="center"><font size="4">论文上传</font> </p>
<form name="form1" ENCTYPE="multipart/form-data" method="post" action="adddata.php?db=<? echo $db ?>&tb=<? echo $tb ?>">
<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="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">
</font></div>
</td>
</tr>
</table>
</div>
</form>
<?
}//end of pshzl of foljrsxelse
{
?>
<p align="center"><font size="4">录入数据</font> </p>
<form name="form1" ENCTYPE="multipart/form-data" method="post" action="adddata.php?db=<? echo $db ?>&tb=<? echo $tb ?>">
<div align="center">
<table width="75%" border="0">
<tr>
<td>文章标题:
<input type="text" name="title" size="40">
作者:
<input type="text" name="author">
</td>
</tr>
<? if((($db=="foltyx"&&$tb=="wlg_master")||($db=="foljrsx"&&$tb=="pshzl"))||($db=="foljrxt"&&($tb!="hbyh"&&$tb!="tzlc")))
{
?>
<tr>
<td>
<p align="left">简短介绍:
<textarea name="summary" cols="80" rows="3"></textarea>
</p>
</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>
<? if((($db=="foltyx"&&$tb=="wlg_master")||($db=="foljrbd"&&$tb=="tpxw"))||($db=="foljrxt"&&($tb=="shpx"||$tb=="tswl")))
{
?>
<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">
</font></div>
</td>
</tr>
</table>
</div>
</form>
<?
}
?>
</body>
</html>
<html>
<head>
<title>增加数据</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#FFFFFF">
<?
@$link=mysql_pconnect("localhost","root","rpass007") or
die ("登陆服务器失败,请稍候再试");
mysql_select_db($db);
$date=date('Y-m-d H:i:s');
if((($db=="foltyx"&&$tb=="wlg_master")||($db=="foljrbd"&&$tb=="tpxw"))||($db=="foljrxt"&&($tb=="shpx"||$tb=="tswl")))//for tyx jrbd jrxt
{
if(chop($imagein)!="none")
{
$picuppath="/home/fol/php/admin/"; //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($db=="foljrbd"&&tb=="tpxw"){//there is no summary in tpxw of foljrbd,so ...
$result =mysql_query("insert into $tb (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 $tb (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($db=="foljrbd"&&$tb=="cjzt"){//beggin of cjzt of fol jrbd
$result =mysql_query("insert into $tb (title,content,date,author,origin,topic) values('$title','$content','$date','$author','$origin','$topic')",$link);
}//end of cjzt of fol jrbd
elseif($db=="foljrsx"&&$tb=="pshzl")//for jrsx
{
if(chop($imagein)!="none")
{
$picuppath="/home/fol/php/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 $tb (title,content,date,author,origin,artcloldname,artcltype,artclname) values('$title','$content','$date','$author','$origin','$imgoldname','$imgtype','$imgname')",$link);
}
else die("请上传论文");
}//end of art
elseif($db=="foljrxt"&&($tb=="ztjz"||$tb=="alfx")){
$result =mysql_query("insert into $tb (title,summary,content,date,author,origin) values('$title','$summary','$content','$date','$author','$origin')",$link);
}
else{
$result =mysql_query("insert into $tb (title,content,date,author,origin) values('$title','$content','$date','$author','$origin')",$link);
}
if (mysql_affected_rows()==1)
{
?>
添加成功,请返回!
<p><a href="add.php?db=<? echo $db ?>&tb=<? echo $tb ?>">返回</a> </p>
<?
}
else
{
?>
添加不成功,请稍候再试!
<p><a href="add.php?db=<? echo $db ?>&tb=<? echo $tb ?>">返回</a> </p>
<?
}
?></body>
</html>
你可以参考一下,具体的数据库得根据自己的需要来处理
浅妄薄见,望与斟酌
而是以数据库作为管理图片的手段楼上的写得很不错。这是我写的一个小程序,你看看,如果需要,可以mail我给你代码
http://ggajj.net/pc9710/alamb/alamb.php
如果要代码:留下email
[email protected]
我的不是利用服务器存储的图片吗?我一直用它来实现这个功能啊,呵呵现在的服务器速度都很快,用数据库存储图片只是用了一个echo $图片内容;
语句,所有的工作都交给浏览器来执行了,所以不会太大的影响速度--这是我的看法。
浅妄薄见,望与斟酌