PHP gets the picture in the folder path and the example of pagination display

Source: Internet
Author: User
Tags prev

  This article mainly describes the PHP to get the folder path in the picture and pagination display examples, the need for friends can refer to the following

  Code as follows: <div style= "width:90%; margin:10px Auto; border:1px solid #ccc; Text-align:center ">     <?php     $page =isset ($_get[' page ')" $_get[' page ']:0;//from zero-start   & nbsp $imgnums = 10;    //The number of pictures per page     $path = "Upload";  //Picture saved directory     $handle = Opendir ($path);     $i = 0;     while (false!== ($file = Readdir ($handle)) {       list ($filesname, $ext) =explode ("." , $file);        if ($ext = = "gif" or $ext = = "jpg" or $ext = = "jpg" or $ext = "gif") {        &NB Sp  if (!is_dir ('./'. $file)) {              $array []= $file;//Save picture name     &N Bsp         + + $i;                        }       if ($array) {& nbsp      rsort ($array);//Modify date reverse order    }     for ($j = $imgnums * $page; $j < ($imgnums * $page + $imgnums) && $j < $i; + + $j) {       echo ' <div> ';        echo $array [$j], ' <br/> ';   &N Bsp    echo "<img src=". $path. " /". $array [$j]." ><br/> ";        echo ' </div> ';    }     $realpage = @ceil ($i/$imgnums)-1;     $Prepage = $page-1;     $Nextpage = $page +1;     if ($Prepage <0) {       echo "prev";        echo "<a href=?page= $Nextpage > next page </a>";        echo "<a href=?page= $realpage > last page </a>";    }elseif ($Nextpage >= $realpage) {       echo "<a href=?page=0> home </a>";        echo "<a href=?page= $Prepage > Prev </a>";        echo "next page";    }else{       echo "<a href=?page=0> home </a>";       echo "<a href=?page= $Prepage > Prev </a>";        echo "<a href=?page= $Nextpage > next page </a>";        echo "<a href=?page= $realpage > last page </a>";    }    ?> </div>  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.