欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP上传单张图片

程序员文章站 2022-04-11 18:03:29
...
PHP上传单张图片到服务器,如下代码:
  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.comtitle>
  8. head>
  9. body>
  10. table width="355" height="240" border="0" align="center" cellpadding="0" cellspacing="0">
  11. tr>
  12. td width="106" height="100"> td>
  13. td width="196"> td>
  14. td width="31"> td>
  15. tr>
  16. form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data">
  17. tr>
  18. td height="30" align="center"> td>
  19. td valign="middle">input name="images" type="file" id="images2" size="15">
  20. input type="hidden" name="MAX_FILE_SIZE" value="30000"> td>
  21. td> td>
  22. tr>
  23. tr>
  24. td height="55"> td>
  25. td>input type="submit" name="Submit" value="提交">td>
  26. td> td>
  27. tr>
  28. form>
  29. tr>
  30. td height="55"> td>
  31. td> td>
  32. td> td>
  33. tr>
  34. table>
  35. table width="355" border="1" align="center" cellpadding="0" cellspacing="0">
  36. php $query="select * from tb_image2 where id order by data desc limit 2";
  37. $result=mysql_query($query);
  38. if($result==true){
  39. while($myrow=mysql_fetch_array($result)){
  40. ?>tr>
  41. td width="100" align="center">php echo $myrow[data];?>td>
  42. td width="255" align="center">img src="" width="200" height="150">td>
  43. tr>
  44. php }}?>
  45. table>
  46. body>
  47. html>

conn.php:

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

index_ok.php:

  1. session_start();
  2. include("conn.php");?>
  3. if($Submit=="提交"){
  4. $data=date("Y-m-d");
  5. $filesize=$_FILES['images']['size'];
  6. if($filesize>1000000)
  7. {echo "";}else{
  8. $path = 'upfiles/'. $_FILES['images']['name'];
  9. if (move_uploaded_file($_FILES['images']['tmp_name'],$path)) {
  10. $query1="insert into tb_image2(path,data,image_name)values('$path','$data','$images')";
  11. $result1=mysql_query($query1);
  12. if($result1=true){
  13. echo "上传成功!!";
  14. echo "";
  15. }else{echo "文件上传失败!!";
  16. echo "";}
  17. }}}
  18. ?>