求一个PHP分页显示图片的代码
要用PHP分页显示文件夹中的图片。。代码该怎么写。。网上找了很久找到的也用不了
回复讨论(解决方案)
循环获取文件名 然后用html代码输出就行了.
额。。妞妞大人。。我表示完全不会
找个分页类,一用。
你们说的我都没看懂。。
你是分页不会还是读取图片显示不会呢?
你是分页不会还是读取图片显示不会呢?
分页你可以将图片名都读出到数组,如果不是非常多,序列化到session,然后再按照数组的数量进行分配页数.
每页再输出按照key分组的内容就可以了。
你是分页不会还是读取图片显示不会呢?
分页你可以将图片名都读出到数组,如果不是非常多,序列化到session,然后再按照数组的数量进行分配页数.
每页再输出按照key分组的内容就可以了。
我是两个都不会。。我最近自学PHP..这两天在做一个企业网站..其他的摸索摸索都做差不多了..就卡在分页这..
妞大。。你这些是存在类里然后调用吗?
妞大。。你这些是存在类里然后调用吗?
0.0
这个是函数
使用方法在后面
$imgArray = getDir('../Images');//读取Images这个目录下的所有图片文件返回给数组 imgArray
//循环数组输出值,根据自己需要设置显示的html
foreach ($imgArray as $value) {
echo '

';
}
<?phpecho "<html><head><title>图片</title></head><body bgcolor=000000><center><font size=2 color=red>";//输出html相关代码$page=$_GET['page'];//获取当前页数$max=3;//设置每页显示图片最大张数$handle = opendir('./'); //当前目录 while (false !== ($file = readdir($handle))) { //遍历该php文件所在目录 list($filesname,$kzm)=explode(".",$file);//获取扩展名 if($kzm=="gif" or $kzm=="jpg" or $kzm=="JPG") { //文件过滤 if (!is_dir('./'.$file)) { //文件夹过滤 $array[]=$file;//把符合条件的文件名存入数组 $i++;//记录图片总张数 } } }for ($j=$max*$page;$j<($max*$page+$max)&&$j<$i;++$j){//循环条件控制显示图片张数 echo "<img widht=800 height=600 src=\"$array[$j]\" alt="求一个PHP分页显示图片的代码" ><br>";//输出图片数组}$Previous_page=$page-1;$next_page=$page+1;if ($Previous_page<0){ echo "上页"; echo "<a href=?page=$next_page>下页</a>";} else if ($page<=$i/$max){ echo "<a href=?page=$Previous_page>上页</a>"; echo "<a href=?page=$next_page>下页</a>";} else{ echo " <a href=?page=$Previous_page>上页</a>"; echo "下页"; }echo "</center></body></html>";?>妞大。。我找的这个可以用吗?半懂半不懂的
应该可以 问题是为了分页hh每次都要遍历一次目录比较蛋痛.如果用的不频繁就无所谓了,如果调用程度很高的话还是读取一次保存到数据库去 然后调用比较合适。当然也可以用memcache来保存数据,不过跟你说这个可能不容易理解
确实不容易理解。。我图片大概30来张。。用刚我找的那个分页的勉强能理解。。就是改路径不知道怎么改。。有点小郁闷。。我PHP在这个路径E:\nanfan\www\tmp\1\1 然后图片在这个路径E:\nanfan\www\tmp\1\1\产品..哎。。分页要我命啊
http://www.hh595.com/product.php 我是想做出类似这样的效果。。摸索两三天了。。丁点进展都没。。差点就想用HTML来一个图一个图搞上去了。。然后一个图配个PHP。。
阿门。。各位大大们帮帮我吧
阿门。。各位大大们帮帮我吧
我擦,30来张还分页?你一页要显示几个?是高清无码吗?
引用 15 楼 kjkjq520 的回复:
阿门。。各位大大们帮帮我吧
我擦,30来张还分页?你一页要显示几个?是高清无码吗?
一页显示8张。。因为我还要设置链接。。点进去看产品的详细信息
http://www.hh595.com/product.php 妞大你看看这个的。。我就是要做那个效果。。可惜实力不够
阿门。。各位大大们帮帮我吧
明智的做法是把你的图片的路径存进数据库。从数据库取数据分页就容易多了。额。。问题是不会。。妞大乔大。。真心求教育
分页类。网上多了。
http://www.google.com.hk/#hl=zh-CN&safe=strict&site=&q=php+%E5%88%86%E9%A1%B5%E7%B1%BB&oq=php+%E5%88%86%E9%A1%B5%E7%B1%BB&aq=f&aqi=&aql=&gs_sm=3&gs_upl=584l3087l0l3323l5l5l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=503abead1d20a8e5&biw=1920&bih=976
你的图片是对应不同的商品的,所以不仅仅是将图片输出就完事的事情,你得跟你的数据库结合起来保存到数据库里才对,这样以后修改,更新都方便。如果你确实都不会
那么就按照你的思路人肉去做吧,30个不多,刚我已经把你要的输出目录图片功能写了一大部分了,再去看看你要的页面效果,我发现不能简单那的输出就结束了,必须跟数据库结合起来。这样的话要么入库要么人肉。而不是将目录的图片读出来显示,最正确的做法是读取数据库里的商品信息将商品的信息列出来。
if(strlen($upload_file1_name)>0 && $ppd->ID>0) { $file_size_max = 6400000;// 限制文件上传最大容量(bytes) $accept_overwrite = true;//允许读写文件 if (! @ copy($upload_file1,$store_dir . $upload_file1_name)) //复制文件到指定目录 { echo "复制文件失败"; } $Picture=$upload_file1; If($Picture != "none") { $PSize = filesize($Picture); //echo $PSize."---<br>"; $mysqlPicture = addslashes(fread(fopen($Picture, "r"), $PSize)); $size = GetImageSize($Picture); $str="update MT_pic set picmsg='$mysqlPicture',p_w='$size[0]',p_h='$size[1]' where mtid='".$ppd->ID."' and edit=0 "; mysql_query($str,$handler); //echo $str; unlink($upload_file1_name); } }
看天数啊。。我晕
$imgs = array_chunk(glob('images/*.{gif,GIF,jpg,JPG,png,PNG}', GLOB_BRACE), 8);
然后将 $imgs 带入到你找到的分页类中
$imgs = array_chunk(glob('images/*.{gif,GIF,jpg,JPG,png,PNG}', GLOB_BRACE), 8);
然后将 $imgs 带入到你找到的分页类中
学习了
图片不多的话,直接把图片路劲集中放到一个变量或文本文件中,在js中用ajax或去每页要显示的图片路径就是了,然后的操作就是js操作了
图片不多的话,直接把图片路劲集中放到一个变量或文本文件中,在js中用ajax或去每页要显示的图片路径就是了,然后的操作就是js操作了
大哥我PHP都不怎么会呢就要我搞JS。。我会屎掉的
引用 26 楼 libo_sina 的回复:
图片不多的话,直接把图片路劲集中放到一个变量或文本文件中,在js中用ajax或去每页要显示的图片路径就是了,然后的操作就是js操作了
大哥我PHP都不怎么会呢就要我搞JS。。我会屎掉的
穿好止尿库 屎就不会掉了...
基本的都不会,你还搞啥!
lz,你砖都没有还想造房子。。。
回去先把基础搞定了吧,别人给你一串代码你居然说看天书。。。。
额,路过,表示沉默,网上一大堆,随便找一个就能用了
这和文章标题分页一样,关键是要把你的图片路径及相关信息写进数据库 然后再分页显示就好了 这样最简单的方法
<?phpecho 'sxxxxxxxxxxs';?>
先把图片名存到数据库里面,然后读取写到数组里面,再循环写出就可以了
找个分页类。
你和我刚学习PHP一样,别人给的代码,我看着像天书~~~
我建议,让你身边会PHP的人给 你先写个简单的分页,一点一点教你,学会这个了,再上网找个分页类,自己做一下,能做出来的话,上面妞妞大牛和乔牛给你说的你就懂了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.
