Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 包含特定目录中的照片的图库_Php_Html - Fatal编程技术网

Php 包含特定目录中的照片的图库

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循环可以解决这个问题(不太喜欢Javascript)。有没有一种方法可以使用PHP显示HTML代码中目录中的每张图片?

试试这段代码,它对我有用

<?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>";
?>


欢迎来到我们的网站!对于像这样的基本问题,确保先搜索-你几乎肯定会找到答案:仍然有一些问题,你能再解释一下吗。很抱歉给您带来不便您有什么问题??