Php 包含特定目录中的照片的图库
我正在尝试在网站上创建一个照片库,我希望它能够显示某个目录中的每张照片。我认为PHP循环可以解决这个问题(不太喜欢Javascript)。有没有一种方法可以使用PHP显示HTML代码中目录中的每张图片?试试这段代码,它对我有用Php 包含特定目录中的照片的图库,php,html,Php,Html,我正在尝试在网站上创建一个照片库,我希望它能够显示某个目录中的每张照片。我认为PHP循环可以解决这个问题(不太喜欢Javascript)。有没有一种方法可以使用PHP显示HTML代码中目录中的每张图片?试试这段代码,它对我有用 <?php $imgdir = 'source/'; //Pick your folder $allowed_types = array('png','jpg','jpeg','gif'); //Allowed types of files $dimg = open
<?php
$imgdir = 'source/'; //Pick your folder
$allowed_types = array('png','jpg','jpeg','gif'); //Allowed types of files
$dimg = opendir($imgdir);//Open directory
while($imgfile = readdir($dimg))
{
if( in_array(strtolower(substr($imgfile,-3)),$allowed_types) OR
in_array(strtolower(substr($imgfile,-4)),$allowed_types) )
/*If the file is an image add it to the array*/
{$a_img[] = $imgfile;}
}
echo "<ul>";
$totimg = count($a_img); //The total count of all the images
//Echo out the images and their paths incased in an li.
for($x=0; $x < $totimg; $x++){echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>";}
echo "</ul>";
?>
欢迎来到我们的网站!对于像这样的基本问题,确保先搜索-你几乎肯定会找到答案:仍然有一些问题,你能再解释一下吗。很抱歉给您带来不便您有什么问题??