Get All Photos From Folder and Paginate With PHP(从文件夹中获取所有照片并使用 PHP 进行分页)
问题描述
我正在尝试构建一个具有照片库的站点,而不是构建数据库 CMS,我正在尝试使用 PHP 和文件夹.目前我有一个脚本来获取文件夹中的所有图像并将它们显示在页面上,但是由于可能会超过 100 张照片,我想使用分页将其拆分为多个页面,但是我不知道该怎么做.
这是我目前正在运行的脚本:
问题 1 - 如何提取没有文件扩展名的文件名?Q2 - 对于每页 24 张图片,我该如何分页?
对于分页,您必须计算要分页的总项目数,捕获当前页面的参数并在相应范围内迭代.
您可以使用pathinfo函数来获取不带扩展名的文件名.
';}show_pagination($page, $last_page);
使用以下功能可以创建导航链接
I'm trying to build a site that has a photo gallery and rather than build a database CMS I'm trying it with the use of PHP and folders. At the moment I have a script to get all of the images in a folder and display them on a page, however as there are going to be probably in excess of 100 photo's I'd like to use pagination to spllit this over several pages but I have no idea how to do this.
Here is the script I'm currently running:
Q1 - How do I extract the file name without the file extension? Q2 - How do I paginate this for say 24 images per page?
For paging you must calculate the total items to page , capture the parameter of the current page and iterate over the respective range.
You can use the function pathinfo to get the file name without extension.
Using the following function you can create the navigation links
这篇关于从文件夹中获取所有照片并使用 PHP 进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!