html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

PHP上传单张图片_PHP教程_编程技术

[ ] 已经帮助:人解决问题

PHP上传单张图片到服务器,如下代码:vFHHTML5中文学习网 - HTML5先行者学习网

  1. <?php  
  2. session_start();  
  3. include("conn.php");?> 
  4. <html> 
  5. <head> 
  6. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
  7. <title>上传单图片到服务器并显示 - www.cxybl.com</title> 
  8. </head> 
  9.  
  10. <body> 
  11. <table width="355" height="240" border="0" align="center" cellpadding="0" cellspacing="0"> 
  12.   <tr> 
  13.     <td width="106" height="100"> </td> 
  14.     <td width="196"> </td> 
  15.     <td width="31"> </td> 
  16.   </tr> 
  17. <form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data"> 
  18.   <tr> 
  19.     <td height="30" align="center"> </td> 
  20.     <td valign="middle"><input name="images" type="file" id="images2" size="15"> 
  21.      <input type="hidden" name="MAX_FILE_SIZE" value="30000">   </td> 
  22.     <td> </td> 
  23.   </tr> 
  24.   <tr> 
  25.     <td height="55"> </td> 
  26.     <td><input type="submit" name="Submit" value="提交"></td> 
  27.     <td> </td> 
  28.   </tr> 
  29.  </form> 
  30.   <tr> 
  31.     <td height="55"> </td> 
  32.     <td> </td> 
  33.     <td> </td> 
  34.   </tr> 
  35. </table> 
  36. <table width="355" border="1" align="center" cellpadding="0" cellspacing="0"> 
  37.  <?php $query="select * from tb_image2 where id order by data desc limit 2"
  38.  $result=mysql_query($query); 
  39.  if($result==true){ 
  40.  while($myrow=mysql_fetch_array($result)){  
  41.  ?><tr> 
  42.     <td width="100" align="center"><?php echo $myrow[data];?></td> 
  43.     <td width="255" align="center"><img src="<?php echo $myrow[path];?>" width="200" height="150"></td> 
  44.   </tr> 
  45.   <?php }}?> 
  46. </table> 
  47. </body> 
  48. </html> 

conn.php:vFHHTML5中文学习网 - HTML5先行者学习网

  1. <?php  
  2. $id=mysql_connect('localhost','root','root'); 
  3. mysql_select_db("db_database12",$id); 
  4. mysql_query("set names gb2312"); 
  5. ?> 

index_ok.php:vFHHTML5中文学习网 - HTML5先行者学习网

  1. <?php  
  2. session_start();  
  3. include("conn.php");?> 
  4. <?php 
  5.  if($Submit=="提交"){ 
  6. $data=date("Y-m-d"); 
  7. $filesize=$_FILES['images']['size']; 
  8. if($filesize>1000000) 
  9.   {echo "<script> alert('对不起,您输入的图片太大,不能上传!!'); history.back();</script>";}else
  10. $path = 'upfiles/'$_FILES['images']['name']; 
  11. if (move_uploaded_file($_FILES['images']['tmp_name'],$path)) {  
  12.     $query1="insert into tb_image2(path,data,image_name)values('$path','$data','$images')"
  13.     $result1=mysql_query($query1); 
  14.     if($result1=true){  
  15.     echo "上传成功!!"
  16.     echo "<meta http-equiv=/"Refresh/" content=/"3;url=index.php/">";  
  17.     }else{echo "文件上传失败!!"
  18.           echo "<meta http-equiv=/"Refresh/" content=/"3;url=index.php/">";} 
  19. }}} 
  20. ?> 
vFHHTML5中文学习网 - HTML5先行者学习网
vFHHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助