PHP上传文件到服务器 并显示
1先说一下php环境搭建,我是用的是appserv菜鸟级产品 直接安装就可以了 注意记住mysql的密码 mysql的 帐号是root1上传代码
01<formname="form1"method="post"action="index_ok.php"enctype="multipart/form-data">
02<tr>
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>
06<td> </td>
07</tr>
08<tr>
09<tdheight="55"> </td>
10<td><inputtype="submit"name="Submit"value="提交"></td>
11<td> </td>
12</tr>
13</form>
上传显示提醒页面写入数据库的代码
01<?phpsession_start();include("conn/conn.php");?>
02<?php
03if($Submit=="提交"){
04$data=date("Y-m-d");
05$filesize=$_FILES['images']['size'];
06if($filesize>1000000){echo"<script>alert('对不起,您输入的图片太大,不能上传!!'); history.back();</script>";}else{
07$path='upfiles/'.$_FILES['images']['name'];
08if(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);
11if($result1=true){
12echo"上传成功!!";
13echo"<metahttp-equiv=\"Refresh\" content=\"3;url=index.php\">";
14}else{echo"文件上传失败!!";
15echo"<metahttp-equiv=\"Refresh\" content=\"3;url=index.php\">";}
16}}}
17?>
所包含的连接数据库的配置文件
1<?php
2$id=mysql_connect('localhost','root','1');//主机名字用户 密码
3mysql_select_db("db_database12",$id);//选择数据库
4mysql_query("setnames gb2312");//设置编码
5?>
遍历然后显示图片的代码
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);
04if($result==true){
05while($myrow=mysql_fetch_array($result)){
06?><tr>
07<tdwidth="100"align="center"><?phpecho$myrow;?></td>
08<tdwidth="255"align="center"><imgsrc="<?phpecho $myrow;?>"width="200"height="150"></td>
09</tr>
10<?php}}?>
11</table>
页:
[1]