如何从文件夹中逐个获取图片并使用PHP在页面中显示 [英] How to get the pictures from folder one by one and display in the page using PHP

查看:603
本文介绍了如何从文件夹中逐个获取图片并使用PHP在页面中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从文件夹中获取图像并将其显示在页面中,是否可以在php中调整大小,或者我必须调整大小并上传它以便以缩略图的形式显示它?

How to fetch the images from a folder and display it in the page, whether i can resize it in php itself or i have to resize it and upload it separtely to display it as thumbnails?

推荐答案

以下是遍历目录并对图像文件执行操作的基本结构(给定'images'是脚本的同一目录中的目录)

Here's the basic structure for traversing a directory and doing something with the image files (given 'images' is a directory in the same directory of your script)

$image_types = array(
    'gif' => 'image/gif',
    'png' => 'image/png',
    'jpg' => 'image/jpeg',
);

foreach (scandir('images') as $entry) {
    if (!is_dir($entry)) {
        if (in_array(mime_content_type('images/'. $entry), $image_types)) {
            // do something with image
        }
    }
}

从这里,您可以将图像直接发送到浏览器,为HTML页面生成标签或使用 GD功能并存储它们以供显示。

From here, you can send the images directly to browser, generate tags for HTML page or create thumbnails with GD functions and store them for displaying.

这篇关于如何从文件夹中逐个获取图片并使用PHP在页面中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆