当前目录中的图像未显示 [英] Images from current directory are not being shown

查看:66
本文介绍了当前目录中的图像未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php脚本显示当前目录中的所有图像。显示图像的php文件也在同一目录中。这是脚本

 <?php  
$ dir = basename(__ DIR__);
if (file_exists($ dir)== false)
{
echo ' 目录\''。 $目录。 ' \'not found!';
}
else {
$ dir_contents = scandir($ dir);
foreach ($ dir_contents as $ file)
{
< span class =code-sdkkeyword> $ file_type = strtolower(end(explode(' 。',$ file)));


if ($ file!== ' 。'&& $ file !== ' ..'&& in_array($ file_type,$ file_display)== true)
{
echo ' < img src ='。$ dir。< span class =code-string>' /'。$ file。' < span class =code-string>alt ='。$ file。' /> ;'; }
?>



输出显示no目录存在。但我已经看到该目录存在。请告诉我我的代码有什么问题谢谢

解决方案

dir = basename(__ DIR__);
if (file_exists(


dir)== false)
{
echo ' 目录\''

DIR。 ' \'not found!';
}
else {


I am trying to show all images from my current directory using php script. the php file which is showing image also is in the same directory. here is the script

<?php 
$dir =basename(__DIR__);
if (file_exists($dir) == false) 
{  
echo 'Directory \''. $dir. '\' not found!'; 
}
else{
$dir_contents = scandir($dir);  
foreach ($dir_contents as $file) 
 {     
 $file_type = strtolower(end(explode('.', $file)));    


if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true)
 {          
echo '<img src="'.$dir. '/'.$file. '" alt="'.$file. '" />';     }    }  }   
 ?>


the output says the no directory exists. but i have seen the directory exists. please tell me whats wrong with my code Thanks

解决方案

dir =basename(__DIR__); if (file_exists(


dir) == false) { echo 'Directory \''.


dir. '\' not found!'; } else{


这篇关于当前目录中的图像未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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