• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2018-06-21) 135次浏览 已收录 0个评论

php上传图片并分页显示,如下代码:

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

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

index_ok.php:

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

欢迎大家阅读《PHP上传多张图片并分页显示_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址