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

PHP上传多张图片并分页显示

程序员文章站 2022-04-26 10:17:49
...
PHP上传图片并分页显示,如下代码:
  1. $id=mysql_connect('localhost','root','root');
  2. mysql_select_db("db_database12",$id);
  3. mysql_query("set names gb2312");
  4. ?>

index.php:

  1. php
  2. session_start();
  3. include "conn.php";
  4. if ($page=="")
  5. {$page=1;};
  6. ?>
  7. html>
  8. head>
  9. meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  10. title>上传多图片到服务器并分页显示 - www.cxybl.comtitle>
  11. style type="text/css">
  12. style>
  13. head>
  14. body>
  15. table width="450" height="259" border="0" cellpadding="0" cellspacing="0">
  16. tr>
  17. td width="134" height="68"> td>
  18. td width="204"> td>
  19. td width="104"> td>
  20. tr>
  21. form action="index_ok.php" method="post" enctype="multipart/form-data" name="form1">
  22. tr>
  23. td height="30"> td>
  24. td>input name="file[]" type="file" size="18">td>
  25. td> td>
  26. tr>
  27. tr>
  28. td height="30"> td>
  29. td>input name="file[]" type="file" size="18">td>
  30. td> td>
  31. tr>
  32. tr>
  33. td height="30"> td>
  34. td>input name="file[]" type="file" size="18">td>
  35. td> td>
  36. tr>
  37. tr>
  38. td height="42"> td>
  39. td align="center">input name="Submit" type="submit" id="Submit" value="提交">td>
  40. td> td>
  41. tr>
  42. form>
  43. tr>
  44. td height="60"> td>
  45. td> td>
  46. td> td>
  47. tr>
  48. table>
  49. table width="450" border="0" cellspacing="0" cellpadding="0">
  50. php if ($page){
  51. $page_size=4;
  52. $query="select count(*) as total from tb_image2 where id";
  53. $result=mysql_query($query);
  54. $message_count=@mysql_result($result,0,"total");
  55. $page_count=ceil($message_count/$page_size);
  56. $offset=($page-1)*$page_size;
  57. for ($i=1; $i=2; $i++) {
  58. echo "tr>";
  59. ?>
  60. php if ($i==1) {
  61. $query="select * from tb_image2 where id order by data desc limit $offset, $page_size";
  62. $result=mysql_query($query);}
  63. $j=1;
  64. while ($myrow=mysql_fetch_array($result)){
  65. if ($j=2){ ?>
  66. td height="150" colspan="2" align="center" valign="middle">
  67. table width="225" height="150" border="0" cellspacing="0">
  68. tr align="center" valign="middle">
  69. td width="225" height="125" align="center" valign="middle">
  70. php echo "img src=\"$myrow[path]\" width=\"224\" height=\"120\">"?>td>
  71. tr>
  72. tr align="left" valign="top">
  73. td height="25" align="center" valign="middle">
  74. span class="style1">php echo $myrow[data];?>span>
  75. td>
  76. tr>
  77. table>td>
  78. php }
  79. ++$j;
  80. if ($j==3){
  81. break;
  82. }}
  83. echo "tr>"; }
  84. ?>
  85. table>
  86. table width="450" border="0" cellspacing="0" cellpadding="0">
  87. tr>
  88. td width="50%" class="style1"> 页次:php echo $page;?>
  89. / php echo $page_count;?> 页 记录:php echo $message_count;?>
  90. td>
  91. td width="39%" class="style1"> 分页:
  92. php
  93. $xsoudh="id=$id";
  94. $next=$ljjl*10;
  95. $n=$ljjl-1;
  96. $m=$ljjl+1;
  97. $prev_page=$page-10;
  98. if ($ljjl==0){ echo "";
  99. }else{
  100. echo "a href='$PATH_INFO?vv=0&ljjl=0&page=1&$xsoudh'>首页a> ";
  101. $ccc=$vv-10;
  102. echo "a href='$PATH_INFO?vv=$ccc&ljjl=$n&page=$prev_page&$xsoudh'>上十页a>";
  103. }?>
  104. php
  105. for ($j=1;$j=$page_count;$j++) {
  106. $pnext=$next+$j;
  107. if ($mm==10){ break; }
  108. if ($mm>$page_count){ break;}
  109. if ($page_count-$vv10){
  110. if ($mm>=$page_count-$vv){break;}
  111. } ?>
  112. php
  113. echo "a href='$PATH_INFO?vv=$vv&ljjl=$ljjl&page=$pnext&$xsoudh'> $pnext a>";
  114. $mm=$mm+1;
  115. }
  116. ?>
  117. td>
  118. td width="11%" class="style1">
  119. php $vv=$vv+$mm;
  120. if ($page_count-$vv=0){ echo "";
  121. }else{
  122. echo "a href='$PATH_INFO?vv=$vv&ljjl=$m&page=$pnext&$xsoudh'>下十页a>";
  123. }
  124. if ($message_count==0){ echo "没有记录!";}
  125. }?>
  126. td>
  127. tr>
  128. table>
  129. body>
  130. html>

index_ok.php:

  1. session_start();
  2. include "conn.php";
  3. ?>
  4. if($_POST["Submit"]!=""){
  5. if(!is_dir("./upfile")){
  6. mkdir("./upfile");}
  7. for($i=0;$icount($file);$i++){
  8. $path="upfile/".date("Ymdhis").$_FILES["file"]["name"][$i];
  9. move_uploaded_file($_FILES["file"]["tmp_name"][$i],$path);
  10. $data=date("Y-m-d H:m:s");
  11. $query="insert into tb_image2 (path,data) values ('$path','$data')";
  12. //创建插入图片数据的sql语句
  13. $result=mysql_query($query);}
  14. echo "图片上传成功,请稍等...";
  15. echo "";}
  16. ?>