dongli2000 2011-10-30 15:46
浏览 37
已采纳

从文件夹中显示文件作为缩略图php

Im trying to rezise some images that are imported from a folder. It doesent matter if it only show the realpicture as a thumbnail since the size of the file wont be much larger than 500kb,

Is there a way I can make the images as clickable images ? I have google it , but cant seem to find a solution that helps me.

This is the code that reads from the folder

$files = glob("uploads/*.*"); 

for ($i=1; $i<count($files); $i++) 
{
     $num = $files[$i];
     echo '<img src="'.$num.'" alt="random image">'."&nbsp;&nbsp;";      
}
  • 写回答

2条回答 默认 最新

  • doujingya1166 2011-10-30 15:55
    关注

    I'm not sure how to actually resize the images with PHP to reduce the file size, but to make the browser render them at a small 'thumbnail' size just add a CSS class attribute to the images that are pushed out. Something like this:

    echo '<img class="thumb" src="'.$num.'" alt="random image">'."&nbsp;&nbsp;";
    

    Then, just add some CSS for the img.thumb class to the top of your document, or wherever you have the rest of your CSS:

    img.thumb
    {
    width:50px;
    height:50px;
    }
    

    If you want the images to by clickable (presumably linking to the full-size image), just wrap anchor tags around your img tags when echo'ing to the document. Something like this:

    echo '<a href="' . $num . '"><img src="'.$num.'" alt="random image"></a>'."&nbsp;&nbsp;";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题