<? @$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> <? } ?> 具体的地方需要你自己改一下浅妄薄见,望与斟酌
我的方法是:
先用copy函数把上传的文件复制到你有权限操作的目录下面
,然后fopen函数打开文件,用fread函数读取图片,得到$string,用base64_encode()函数加密$string然后把这个$string 和你的文字一起插入到数据库,显示的时候用base64_decode()解密显示图片
或者自己在程序里加个函数set_time_limit(120)
<?
@$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>
<?
}
?>
具体的地方需要你自己改一下浅妄薄见,望与斟酌