PHP上传文件到服务器 并显示
1 |
先说一下php环境搭建,我是用的是appserv
菜鸟级产品 直接安装就可以了 注意记住mysql的密码 mysql的 帐号是root |
1 |
上传代码 |
01 |
<form
name="form1" method="post" action="index_ok.php" enctype="multipart/form-data"> |
02 |
<tr> |
03 |
<td
height="30" align="center"> </td> |
04 |
<td
valign="middle"><input
name="images" type="file" id="images2" size="15"> |
05 |
<input
type="hidden" name="MAX_FILE_SIZE" value="30000">
</td> |
06 |
<td> </td> |
07 |
</tr> |
08 |
<tr> |
09 |
<td
height="55"> </td> |
10 |
<td><input
type="submit" name="Submit" value="提交"></td> |
11 |
<td> </td> |
12 |
</tr> |
13 |
</form> |
上传显示提醒页面写入数据库的代码
01 |
<?php
session_start(); include("conn/conn.php");?> |
02 |
<?php |
03 |
if($Submit=="提交"){ |
04 |
$data=date("Y-m-d"); |
05 |
$filesize=$_FILES['images']['size']; |
06 |
if($filesize>1000000){echo "<script>
alert('对不起,您输入的图片太大,不能上传!!'); history.back();</script>";}else{ |
07 |
$path = 'upfiles/'. $_FILES['images']['name']; |
08 |
if (move_uploaded_file($_FILES['images']['tmp_name'],$path))
{ |
09 |
$query1="insert
into tb_image2(path,data,image_name)values('$path','$data','$images')"; |
10 |
$result1=mysql_query($query1); |
11 |
if($result1=true){ |
12 |
echo "上传成功!!"; |
13 |
echo "<meta
http-equiv=\"Refresh\" content=\"3;url=index.php\">"; |
14 |
}else{echo "文件上传失败!!"; |
15 |
echo "<meta
http-equiv=\"Refresh\" content=\"3;url=index.php\">";} |
16 |
}}} |
17 |
?> |
1 |
<?php |
2 |
$id=mysql_connect('localhost','root','1');//主机名字
用户 密码 |
3 |
mysql_select_db("db_database12",$id); //选择数据库 |
4 |
mysql_query("set
names gb2312"); //设置编码 |
5 |
?> |
遍历然后显示图片的代码
01 |
<table
width="355" border="1" align="center" cellpadding="0" cellspacing="0"> |
02 |
<?php $query="select
* from tb_image2"; |
03 |
$result=mysql_query($query); |
04 |
if($result==true){ |
05 |
while($myrow=mysql_fetch_array($result)){ |
06 |
?><tr> |
07 |
<td
width="100" align="center"><?php echo $myrow[data];?></td> |
08 |
<td
width="255" align="center"><img
src="<?php
echo $myrow[path];?>" width="200"height="150"></td> |
09 |
</tr> |
10 |
<?php
}}?> |
11 |
</table> |

浙公网安备 33010602011771号