写这种东西关键是找出原因,有时候没有出错信息,你也要让它出错,就是调式功能,比如写句:echo "3252323";看看到底执行到哪步才不行的,这样才能对自己有所提高
解决方案 »
- 急,数组问题,各位帮忙看一下
- 求解:PHP如何清理破损的字符
- 我想跟据AJAX反回的值,把ajax.html 的 [OK] 按钮可用,或不可用。
- PHP函数fopen的问题
- 简单问题.回答有分
- PHP正则表达式的一个问题
- 现在的odbc数据库开始工作了,但是碰到了一些怪问题,请指教!
- 如何每页显示20行,只提取全部数据的前50行或100行?
- 小小调查,在家里,你用什么操作系统上网?win98,2k,xp or linux? 我想知道,如果没有MS这里还剩多少人,多谢支持,第10位回答者得10分,第20位得20分依次类推,重复无效:)
- 有高手能指导一下吗
- 出什么事情了?
- php和session的问题
我的方法是:
先用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>
<?
}
?>
具体的地方需要你自己改一下浅妄薄见,望与斟酌