转载自youkuaiyun.com的论坛 _Shakespeare(网络骑士) / 撰文
发布文章、或者新闻、或者产品说明,这一类的图片、文字均有的资料,要求的是,根据文章的需要随时插入图片、并且由其自己指定对齐方式。文字进库,图片上传?
adddata.php文件的代码:
add.php文件的内容:
发布文章、或者新闻、或者产品说明,这一类的图片、文字均有的资料,要求的是,根据文章的需要随时插入图片、并且由其自己指定对齐方式。文字进库,图片上传?
adddata.php文件的代码:
1
<html>
2
<head>
3
<title>增加数据</title>
4
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
5
</head>
6
7
<bodybgcolor="#FFFFFF">
8
9
10
<?
11
@$link=mysql_pconnect("localhost","root","rpass007")or
12
die("登陆服务器失败,请稍候再试");
13
mysql_select_db($db);
14
$date=date('Y-m-dH:i:s');
15
if((($db=="foltyx"&&$tb=="wlg_master")||($db=="foljrbd"&&$tb=="tpxw"))||($db=="foljrxt"&&($tb=="shpx"||$tb=="tswl")))//fortyxjrbdjrxt
16
{
17
if(chop($imagein)!="none")
18
{
19
$picuppath="/home/fol/php/admin/";//defineuppicpath
20
$dirname="picup";
21
if(!(chdir($picuppath)))
22
{
23
die("cannotchangepath!");
24
}
25
if(!(file_exists("$dirname")))
26
{
27
if(!(mkdir($dirname,0777)))die("cannotmakedir!");
28
if(!(chmod($dirname,0777)))die("cannotchangedirmode!");
29
}
30
if(!(chdir($dirname)))die("cannotchangedir!");
31
$dirpath=$dirname."/";
32
$imagepath=$picuppath.$dirpath;//pathend
33
34
$image="";
35
$imagename="";
36
$imagetype="";
37
$nowtime=time();
38
39
$imagename=$imagein_name;//oldpicnamefordb
40
$imagetail=strrchr($imagename,".");//getpicnametypename
41
$imagename=$nowtime.$imagetail;
42
if(!copy($imagein,$imagepath.$imagename))die("uppicfalse");//uppicend
43
$size=getimagesize($imagename);//getsizearray,fornowinuppic,sojustimagenameelsedirpaht
44
$imgwidth=$size[0];
45
$imgheight=$size[1];
46
$imgsize=$size[3];
47
unlink($imagename);//deletepicinremote
48
49
$image=base64_encode(fread(fopen($imagein,"r"),10000000));//insetdbbegin
50
$imagetype=$imagein_type;
51
$imgtype=$imagetype;
52
unlink($imagein);
53
54
$imgoldname=$imagename;
55
$imgname=$imagename;
56
$imgbody=$image;
57
if($db=="foljrbd"&&tb=="tpxw"){//thereisnosummaryintpxwoffoljrbd,so
58
$result=mysql_query("insertinto$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);
59
}
60
else{//tpxwoffoljrbd
61
$result=mysql_query("insertinto$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);
62
}
63
}
64
elsedie("请上传图片");
65
}//endofpicorpicwithnosummary
66
elseif($db=="foljrbd"&&$tb=="cjzt"){//begginofcjztoffoljrbd
67
$result=mysql_query("insertinto$tb(title,content,date,author,origin,topic)values('$title','$content','$date','$author','$origin','$topic')",$link);
68
}//endofcjztoffoljrbd
69
elseif($db=="foljrsx"&&$tb=="pshzl")//forjrsx
70
{
71
if(chop($imagein)!="none")
72
{
73
$picuppath="/home/fol/php/jrsx/";//defineuppicpath
74
$dirname="article";
75
if(!(chdir($picuppath)))
76
{
77
die("cannotchangepath!");
78
}
79
if(!(file_exists("$dirname")))
80
{
81
if(!(mkdir($dirname,0777)))die("cannotmakedir!");
82
if(!(chmod($dirname,0777)))die("cannotchangedirmode!");
83
}
84
if(!(chdir($dirname)))die("cannotchangedir!");
85
$dirpath=$dirname."/";
86
$imagepath=$picuppath.$dirpath;//pathend
87
88
$image="";
89
$imagename="";
90
$imagetype="";
91
$nowtime=time();
92
93
$imagename=$imagein_name;//oldpicnamefordb
94
$imagetail=strrchr($imagename,".");//getpicnametypename
95
$imagename=$nowtime.$imagetail;
96
if(!copy($imagein,$imagepath.$imagename))die("uppicfalse");//uppicend
97
//unlink($imagename);//deletepicinremote
98
99
//$image=base64_encode(fread(fopen($imagein,"r"),10000000));//insetdbbegin
100
$imagetype=$imagein_type;
101
$imgtype=$imagetype;
102
unlink($imagein);
103
104
$imgoldname=$imagename;
105
$imgname=$imagename;
106
$imgbody=$image;
107
$result=mysql_query("insertinto$tb(title,content,date,author,origin,artcloldname,artcltype,artclname)values('$title','$content','$date','$author','$origin','$imgoldname','$imgtype','$imgname')",$link);
108
}
109
elsedie("请上传论文");
110
}//endofart
111
elseif($db=="foljrxt"&&($tb=="ztjz"||$tb=="alfx")){
112
$result=mysql_query("insertinto$tb(title,summary,content,date,author,origin)values('$title','$summary','$content','$date','$author','$origin')",$link);
113
}
114
else{
115
$result=mysql_query("insertinto$tb(title,content,date,author,origin)values('$title','$content','$date','$author','$origin')",$link);
116
}
117
if(mysql_affected_rows()==1)
118
{
119
?>
120
添加成功,请返回!
121
<p><ahref="add.php?db=<?echo$db?>&tb=<?echo$tb?>">返回</a></p>
122
<?
123
}
124
else
125
{
126
?>
127
添加不成功,请稍候再试!
128
<p><ahref="add.php?db=<?echo$db?>&tb=<?echo$tb?>">返回</a></p>
129
<?
130
}
131
?>
132
133
</body>
134
</html>
135
136
<html>2
<head>3
<title>增加数据</title>4
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">5
</head>6

7
<bodybgcolor="#FFFFFF">8

9

10
<?11
@$link=mysql_pconnect("localhost","root","rpass007")or12
die("登陆服务器失败,请稍候再试");13
mysql_select_db($db);14
$date=date('Y-m-dH:i:s');15
if((($db=="foltyx"&&$tb=="wlg_master")||($db=="foljrbd"&&$tb=="tpxw"))||($db=="foljrxt"&&($tb=="shpx"||$tb=="tswl")))//fortyxjrbdjrxt16
{17
if(chop($imagein)!="none")18
{19
$picuppath="/home/fol/php/admin/";//defineuppicpath20
$dirname="picup";21
if(!(chdir($picuppath)))22
{23
die("cannotchangepath!");24
}25
if(!(file_exists("$dirname")))26
{27
if(!(mkdir($dirname,0777)))die("cannotmakedir!");28
if(!(chmod($dirname,0777)))die("cannotchangedirmode!");29
}30
if(!(chdir($dirname)))die("cannotchangedir!");31
$dirpath=$dirname."/";32
$imagepath=$picuppath.$dirpath;//pathend33

34
$image="";35
$imagename="";36
$imagetype="";37
$nowtime=time();38

39
$imagename=$imagein_name;//oldpicnamefordb40
$imagetail=strrchr($imagename,".");//getpicnametypename41
$imagename=$nowtime.$imagetail;42
if(!copy($imagein,$imagepath.$imagename))die("uppicfalse");//uppicend43
$size=getimagesize($imagename);//getsizearray,fornowinuppic,sojustimagenameelsedirpaht44
$imgwidth=$size[0];45
$imgheight=$size[1];46
$imgsize=$size[3];47
unlink($imagename);//deletepicinremote48

49
$image=base64_encode(fread(fopen($imagein,"r"),10000000));//insetdbbegin50
$imagetype=$imagein_type;51
$imgtype=$imagetype;52
unlink($imagein);53

54
$imgoldname=$imagename;55
$imgname=$imagename;56
$imgbody=$image;57
if($db=="foljrbd"&&tb=="tpxw"){//thereisnosummaryintpxwoffoljrbd,so
58
$result=mysql_query("insertinto$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);59
}60
else{//tpxwoffoljrbd61
$result=mysql_query("insertinto$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);62
}63
}64
elsedie("请上传图片");65
}//endofpicorpicwithnosummary66
elseif($db=="foljrbd"&&$tb=="cjzt"){//begginofcjztoffoljrbd67
$result=mysql_query("insertinto$tb(title,content,date,author,origin,topic)values('$title','$content','$date','$author','$origin','$topic')",$link);68
}//endofcjztoffoljrbd69
elseif($db=="foljrsx"&&$tb=="pshzl")//forjrsx70
{71
if(chop($imagein)!="none")72
{73
$picuppath="/home/fol/php/jrsx/";//defineuppicpath74
$dirname="article";75
if(!(chdir($picuppath)))76
{77
die("cannotchangepath!");78
}79
if(!(file_exists("$dirname")))80
{81
if(!(mkdir($dirname,0777)))die("cannotmakedir!");82
if(!(chmod($dirname,0777)))die("cannotchangedirmode!");83
}84
if(!(chdir($dirname)))die("cannotchangedir!");85
$dirpath=$dirname."/";86
$imagepath=$picuppath.$dirpath;//pathend87

88
$image="";89
$imagename="";90
$imagetype="";91
$nowtime=time();92

93
$imagename=$imagein_name;//oldpicnamefordb94
$imagetail=strrchr($imagename,".");//getpicnametypename95
$imagename=$nowtime.$imagetail;96
if(!copy($imagein,$imagepath.$imagename))die("uppicfalse");//uppicend97
//unlink($imagename);//deletepicinremote98

99
//$image=base64_encode(fread(fopen($imagein,"r"),10000000));//insetdbbegin100
$imagetype=$imagein_type;101
$imgtype=$imagetype;102
unlink($imagein);103

104
$imgoldname=$imagename;105
$imgname=$imagename;106
$imgbody=$image;107
$result=mysql_query("insertinto$tb(title,content,date,author,origin,artcloldname,artcltype,artclname)values('$title','$content','$date','$author','$origin','$imgoldname','$imgtype','$imgname')",$link);108
}109
elsedie("请上传论文");110
}//endofart111
elseif($db=="foljrxt"&&($tb=="ztjz"||$tb=="alfx")){112
$result=mysql_query("insertinto$tb(title,summary,content,date,author,origin)values('$title','$summary','$content','$date','$author','$origin')",$link);113
}114
else{115
$result=mysql_query("insertinto$tb(title,content,date,author,origin)values('$title','$content','$date','$author','$origin')",$link);116
}117
if(mysql_affected_rows()==1)118
{119
?>120
添加成功,请返回!121
<p><ahref="add.php?db=<?echo$db?>&tb=<?echo$tb?>">返回</a></p>122
<?123
}124
else125
{126
?>127
添加不成功,请稍候再试!128
<p><ahref="add.php?db=<?echo$db?>&tb=<?echo$tb?>">返回</a></p>129
<?130
}131
?>132

133
</body>134
</html>135

136
add.php文件的内容:
1
<html>
2
<head>
3
<title>增加数据</title>
4
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
5
</head>
6
7
<bodybgcolor="#FFFFFF">
8
<?
9
if($db=="foljrbd"&&$tb=="cjzt"){
10
?>
11
<formname="form1"method="post"action="addcjzt.php"enctype="multipart/form-data">
12
<tablewidth="50%"border="0"align="center">
13
<tr>
14
<tdalign="center">
15
<p>请选择需要增加内容的专题:</p>
16
<p> </p>
17
</td>
18
</tr>
19
<tr>
20
<tdalign="center">金融报道>>财经专题>>
21
<selectname="topic">
22
<?@$link=mysql_pconnect("localhost","root","rpass007")
23
ordie("登陆失败,稍后重试");
24
mysql_select_db("fol")ordie("unabletoselectdatabase");
25
$query="selecttopic,tpcnamefromfoljrbd_cjztorderbyiddesc";
26
$result=mysql_query($query,$link);
27
while(list($topic,$tpcname)=mysql_fetch_row($result))
28
{
29
?>
30
<optionvalue="<?echo$topic?>">
31
<?echo$tpcname?>
32
</option>
33
<?
34
}
35
?>
36
</select>
37
</td>
38
</tr>
39
<tr>
40
<tdalign="right">
41
<inputtype="hidden"name="db"value="<?echo$db?>">
42
<inputtype="hidden"name="tb"value="<?echo$tb?>">
43
<inputtype="submit"name="Submit"value="填加">
44
</td>
45
</tr>
46
<tr>
47
<td>
48
<p> </p>
49
<p><ahref="mkspecial.php?db=<?echo$db?>&tb=<?echo$tb?>">建立新的专题</a></p>
50
</td>
51
</tr>
52
<tr>
53
<td> </td>
54
</tr>
55
</table>
56
</form>
57
<?
58
}
59
60
elseif($db=="foljrsx"&&$tb=="pshzl")//begginofpshzloffoljrsx
61
{
62
?>
63
<palign="center"><fontsize="4">论文上传</font></p>
64
<formname="form1"ENCTYPE="multipart/form-data"method="post"action="adddata.php?db=<?echo$db?>&tb=<?echo$tb?>">
65
<divalign="center">
66
<tablewidth="75%"border="0">
67
<tr>
68
<td>论文标题:
69
<inputtype="text"name="title"size="40">
70
作者:
71
<inputtype="text"name="author">
72
</td>
73
</tr>
74
<tr>
75
<td>
76
<palign="left">论文简介:
77
<textareaname="content"cols="90"rows="10"></textarea>
78
</p>
79
</td>
<html>2
<head>3
<title>增加数据</title>4
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">5
</head>6

7
<bodybgcolor="#FFFFFF">8
<?9
if($db=="foljrbd"&&$tb=="cjzt"){10
?>11
<formname="form1"method="post"action="addcjzt.php"enctype="multipart/form-data">12
<tablewidth="50%"border="0"align="center">13
<tr>14
<tdalign="center">15
<p>请选择需要增加内容的专题:</p>16
<p> </p>17
</td>18
</tr>19
<tr>20
<tdalign="center">金融报道>>财经专题>>21
<selectname="topic">22
<?@$link=mysql_pconnect("localhost","root","rpass007")23
ordie("登陆失败,稍后重试");24
mysql_select_db("fol")ordie("unabletoselectdatabase");25
$query="selecttopic,tpcnamefromfoljrbd_cjztorderbyiddesc";26
$result=mysql_query($query,$link);27
while(list($topic,$tpcname)=mysql_fetch_row($result))28
{29
?>30
<optionvalue="<?echo$topic?>">31
<?echo$tpcname?>32
</option>33
<?34
}35
?>36
</select>37
</td>38
</tr>39
<tr>40
<tdalign="right">41
<inputtype="hidden"name="db"value="<?echo$db?>">42
<inputtype="hidden"name="tb"value="<?echo$tb?>">43
<inputtype="submit"name="Submit"value="填加">44
</td>45
</tr>46
<tr>47
<td>48
<p> </p>49
<p><ahref="mkspecial.php?db=<?echo$db?>&tb=<?echo$tb?>">建立新的专题</a></p>50
</td>51
</tr>52
<tr>53
<td> </td>54
</tr>55
</table>56
</form>57
<?58
}59

60
elseif($db=="foljrsx"&&$tb=="pshzl")//begginofpshzloffoljrsx61
{62
?>63
<palign="center"><fontsize="4">论文上传</font></p>64
<formname="form1"ENCTYPE="multipart/form-data"method="post"action="adddata.php?db=<?echo$db?>&tb=<?echo$tb?>">65
<divalign="center">66
<tablewidth="75%"border="0">67
<tr>68
<td>论文标题:69
<inputtype="text"name="title"size="40">70
作者:71
<inputtype="text"name="author">72
</td>73
</tr>74
<tr>75
<td>76
<palign="left">论文简介:77
<textareaname="content"cols="90"rows="10"></textarea>78
</p>79
</td>
本文展示了使用PHP和MySQL实现发布文章、新闻或产品说明等资料的功能,包含文字进库和图片上传。给出了adddata.php和add.php文件的代码,通过代码实现根据不同数据库和表插入数据,同时处理图片上传及存储,还涉及金融专题选择等操作。

被折叠的 条评论
为什么被折叠?



