donglilian0061 2016-01-18 05:21
浏览 125
已采纳

PHP自动上传文件夹中的图像

I'm really beginner in web programming. I want to make webpage which contain photo gallery. This is the code

<body>
    <div class="container">
        <header class="clearfix">
        </header>
        <div class="main">
            <a class="fancybox" href="gallery/1.jpg" data-fancybox-group="gallery" title="Lorem ipsum dolor sit amet"><img src="gallery/1.jpg" alt="" /></a>
            <a class="fancybox" href="gallery/2.jpg" data-fancybox-group="gallery" title="Etiam quis mi eu elit temp"><img src="gallery/2.jpg" alt="" /></a>
            <a class="fancybox" href="gallery/3.jpg" data-fancybox-group="gallery" title="Cras neque mi, semper leon"><img src="gallery/3.jpg" alt="" /></a>
            <a class="fancybox" href="gallery/4.jpg" data-fancybox-group="gallery" title="Lorem ipsum dolor sit amet"><img src="gallery/4.jpg" alt="" /></a>
            <a class="fancybox" href="gallery/5.jpg" data-fancybox-group="gallery" title="Etiam quis mi eu elit temp"><img src="gallery/5.jpg" alt="" /></a>
            <a class="fancybox" href="gallery/6.jpg" data-fancybox-group="gallery" title="Cras neque mi, semper leon"><img src="gallery/6.jpg" alt="" /></a>
            <a class="fancybox" href="gallery/7.jpg" data-fancybox-group="gallery" title="Lorem ipsum dolor sit amet"><img src="gallery/7.jpg" alt="" /></a>
        </div>
    </div>
</body>

I have to type the name of photos manually. But it will be tired if the amount of photos is too much. I want to add php code to upload those images from a folder automatically. How to use php code inside the

<div class="main"></div>

Please give me example.

  • 写回答

3条回答 默认 最新

  • doujiacai4986 2016-01-18 05:37
    关注

    Try this in your <div>: <body> <div class="container"> <header class="clearfix"> </header> <div class="main"> <?php $image_array = array_diff(scandir("images"), array('..', '.')); $i = 0; foreach ($image_array as $key) { ?> <a class="fancybox" href="<?php echo 'images/'.$key; ?>" data-fancybox-group="gallery" title="Lorem ipsum dolor sit amet"> <img src="<?php echo 'images/'.$key; ?>" alt="" height="150" width="150"/></a> <?php $i++; } ?> </div> </div> </body> Change images to your folder name.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c51单片机控制步进电机
  • ¥20 Visual studio无法检测到设备
  • ¥15 为什么我通过html绘制的SVG折线图插入到word中坐标轴不显示出来
  • ¥30 vue 页面窗口放大或者缩小元素会变化
  • ¥15 questasim仿真报错
  • ¥15 寻找电脑攻防的导师,有问题请教一下。
  • ¥20 微信同是win11,我的电脑安装不了pageoffice,一直无法打开
  • ¥15 这个界面我通过postman请求不到,但是通过浏览器可以正常访问
  • ¥15 多目标优化算法在与其他算法数据对比结果判断
  • ¥15 CPTN和EAST,主干网络是VGG16,请问在ICDAR2015数据集上训练之后,CPTN和EAST模型的大小为多少