|
1 | 先说一下php环境搭建,我是用的是appserv菜鸟级产品 直接安装就可以了 注意记住mysql的密码 mysql的 帐号是root |
01 | <formname="form1"method="post"action="index_ok.php"enctype="multipart/form-data"> |
03 | <tdheight="30"align="center"> </td> |
04 | <tdvalign="middle"><inputname="images"type="file"id="images2"size="15"> |
05 | <inputtype="hidden"name="MAX_FILE_SIZE"value="30000"></td> |
09 | <tdheight="55"> </td> |
10 | <td><inputtype="submit"name="Submit"value="提交"></td> |
上传显示提醒页面写入数据库的代码
01 | <?phpsession_start();include("conn/conn.php");?> |
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="insertinto tb_image2(path,data,image_name)values('$path','$data','$images')"; |
10 | $result1=mysql_query($query1); |
13 | echo"<metahttp-equiv=\"Refresh\" content=\"3;url=index.php\">"; |
15 | echo"<metahttp-equiv=\"Refresh\" content=\"3;url=index.php\">";} |
所包含的连接数据库的配置文件
2 | $id=mysql_connect('localhost','root','1');//主机名字用户 密码 |
3 | mysql_select_db("db_database12",$id);//选择数据库 |
4 | mysql_query("setnames gb2312");//设置编码 |
遍历然后显示图片的代码
view source
print?
01 | <tablewidth="355"border="1"align="center"cellpadding="0"cellspacing="0"> |
02 | <?php$query="select* from tb_image2"; |
03 | $result=mysql_query($query); |
05 | while($myrow=mysql_fetch_array($result)){ |
07 | <tdwidth="100"align="center"><?phpecho$myrow[data];?></td> |
08 | <tdwidth="255"align="center"><imgsrc="<?phpecho $myrow[path];?>"width="200"height="150"></td> |
|
|
|