1 | 先说一下php环境搭建,我是用的是appserv
菜鸟级产品直接安装就可以了注意记住mysql的密码mysql的帐号是root |
01 | <form
name= "form1" method= "post" action= "index_ok.php" enctype= "multipart/form-data" > |
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> |
10 | <td><input
type= "submit" name= "Submit" value= "提交" ></td> |
上传显示提醒页面写入数据库的代码
01 | <?php session_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 = "insert intotb_image2(path,data,image_name)values('$path','$data','$images')" ; |
10 | $result1 =mysql_query( $query1 ); |
13 | echo "<meta http-equiv=\"Refresh\"content=\"3;url=index.php\">" ; |
15 | echo "<meta http-equiv=\"Refresh\"content=\"3;url=index.php\">" ;} |
所包含的连接数据库的配置文件
2 | $id =mysql_connect( 'localhost' , 'root' , '1' ); //主机名字 用户密码 |
3 | mysql_select_db( "db_database12" , $id ); //选择数据库 |
4 | mysql_query( "set namesgb2312" ); //设置编码 |
遍历然后显示图片的代码
viewsource
print?
01 | <table
width= "355" border= "1" align= "center" cellpadding= "0" cellspacing= "0" > |
02 | <?php $query = "select *fromtb_image2" ; |
03 | $result =mysql_query( $query ); |
05 | while ( $myrow =mysql_fetch_array( $result )){ |
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> |
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理