读取 php 中目录的内容
Read the content of directory in php
请问我是 php 的初学者,我想读取文件夹中的图像
我的图片名称如下:
image_1_0_0_0.png
image_1_1_0_0.png
image_1_1_1_0.png
.........
.....
image_2_0_0_0.png
image_2_1_0_0.png
image_3_0_0_0.png
我想为以 image_1 _..... 开头的图像分配一种颜色(图像过滤器),为 image_2 _... 分配另一种颜色,为 images_3 ....
然后我只想读取最后一张图像并只检索数字 3,剩下的第一个数字
我想知道怎么做。
读取目录内容:
$dir = "/images/";
$color = "#000000";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "Filename: ".$file."<br>";
if($file[7]=='1') $color="#FF0000";
elseif ($file[7]=='2') $color="#00FF00";
elseif ($file[7]=='3') $color="#0000FF";
else $color="#000000";
// do something with the image
}
closedir($dh);
}
}
我不明白你最后一个问题。
请问我是 php 的初学者,我想读取文件夹中的图像 我的图片名称如下:
image_1_0_0_0.png
image_1_1_0_0.png
image_1_1_1_0.png
.........
.....
image_2_0_0_0.png
image_2_1_0_0.png
image_3_0_0_0.png
我想为以 image_1 _..... 开头的图像分配一种颜色(图像过滤器),为 image_2 _... 分配另一种颜色,为 images_3 ....
然后我只想读取最后一张图像并只检索数字 3,剩下的第一个数字
我想知道怎么做。
读取目录内容:
$dir = "/images/";
$color = "#000000";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "Filename: ".$file."<br>";
if($file[7]=='1') $color="#FF0000";
elseif ($file[7]=='2') $color="#00FF00";
elseif ($file[7]=='3') $color="#0000FF";
else $color="#000000";
// do something with the image
}
closedir($dh);
}
}
我不明白你最后一个问题。