Php codeigniter显示目录中的图像
我正在尝试通过一个函数在浏览器中显示codeigniter代码目录中的所有图像,因此我使用以下代码:Php codeigniter显示目录中的图像,php,image,codeigniter,Php,Image,Codeigniter,我正在尝试通过一个函数在浏览器中显示codeigniter代码目录中的所有图像,因此我使用以下代码: $imgdir = 'upload/'; //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
$imgdir = 'upload/'; //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='http://localhost/code/'" . $imgdir . $a_img[$x] . "' /></li>"; echo $imgdir . $a_img[$x];}
echo "<li><img src='http://localhost/code/upload/corrosivo.jpg' /></li>";
echo "</ul>";
$imgdir='upload/'//选择你的文件夹
$allowed_types=数组('png','jpg','jpeg','gif')//允许的文件类型
$dimg=opendir($imgdir)//开放目录
而($imgfile=readdir($dimg))
{
if(在数组中(strtolower(substr($imgfile,-3)),$allowed_类型)或
在数组中(strtolower(substr($imgfile,-4)),$allowed\u类型)
/*如果文件是图像,请将其添加到数组中*/
{$a_img[]=$imgfile;}
}
回声“”;
$totimg=计数($a\u img)//所有图像的总数
//呼应出安理的影像及其路径。
对于($x=0;$x<$totimg;$x++){echo““echo$imgdir.$a_img[$x];}
回声“”;
回声“
”;
我不明白的是,为什么我在浏览器中的以下位置会出现损坏的图像框:
echo "<li><img src='http://localhost/code/'" . $imgdir . $a_img[$x] . "' /></li>"; echo $imgdir . $a_img[$x];}
echo“”;echo$imgdir$a_img[$x];}
以及:
echo "<li><img src='http://localhost/code/upload/corrosivo.jpg' /></li>";
echo“”;
图像显示成功
我已经验证了变量,并且它们具有正确的内容。您过早地关闭了img标签上的src属性。非常感谢克里斯,真的是这样:D