如何回显目录名 [英] how to echo directory name

查看:150
本文介绍了如何回显目录名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用图像库回显目录名称



此代码显示随机图像,我想用图像回显目录名称,请帮助我解决这个问题。 p>

**我想要这样



示例

  ______________ 
|这个|
|是|
|图像|
| |
| _____________ |
目录名称

**

 <?php 

$ directory =./*/;

//获取带有.jpg扩展名的所有图像文件。
$ images = glob(。$目录。* .jpg);

$ imgs ='';
//创建数组
foreach($ images as $ image){$ imgs [] =$ image; }



// shuffle数组
shuffle($ imgs);

//选择随机数组中的前20个图像
$ imgs = array_slice($ imgs,0,20);

?>



< table id =results>
< tr>
< / tr>
< tr>

<?php $ num_of_files = 0; $ I = 0; foreach($ imgs as $ img):?>
< td>< a href =<?php echo $ img?> target =_ blank>< img class =shadow1name =field-namesrc =<?php echo $ img?> thumb.jpegwidth = 165 height = 135 /> / TD>
<?php if(++ $ num_of_files == 12)break; ?>
<?php if(++ $ i%3 == 0):?>
< / tr>< tr>
<?php endif?>

<?php endforeach?>

< / tr>
< / table>


解决方案

为什么不只是 $ code>< img> 标签下的echo $目录

 < tr> 
<?php foreach($ imgs as $ img):?>
< td>
< a href =<?php echo $ img?>目标= _空白 >
< img class =shadow1name =field-namesrc =<?php echo $ img?> thumb.jpegwidth = 165 height = 135 />
< / a>
< p><?php echo basename($ directory); ?>< / p为H.
< / td>
<?php endforeach; ?>
< / tr>

您在当前范围内是否无权访问此参数?另一个选择是:

 < p><?php echo basename(pathinfo($ img,PATHINFO_DIRNAME)); ?>< / p为H. 


how to echo directory name with images gallery

this code showing random images and i want to echo directory name with images please help me to fix this issue.

**i want like this

example

______________
|     this    |
|     is      |
|    image    |
|             |
|_____________|
 Directory Name

**

<?php

$directory = "./*/";

//get all image files with a .jpg extension.
$images = glob("" . $directory . "*.jpg");

$imgs = '';
// create array
foreach($images as $image){ $imgs[] = "$image"; }



//shuffle array
shuffle($imgs);

//select first 20 images in randomized array
$imgs = array_slice($imgs, 0, 20);

?>



 <table id="results">
            <tr>
            </tr>
<tr>

<?php $num_of_files = 0; $i=0; foreach ($imgs as $img):?>
<td><a href="<?php echo $img ?>" target="_blank"><img class="shadow1" name="field-name" src="<?php echo $img ?>thumb.jpeg" width=165 height=135 /></td>
<?php if (++$num_of_files == 12)break; ?>
  <?php if(++$i%3==0): ?>
    </tr><tr>
  <?php endif ?>

<?php endforeach ?>

</tr>
</table>

解决方案

Why don't you just echo $directory below the <img> tag?

<tr>
   <?php foreach ($imgs as $img): ?>
   <td>
      <a href="<?php echo $img ?>" target="_blank">
         <img class="shadow1" name="field-name" src="<?php echo $img ?>thumb.jpeg" width=165 height=135 />
      </a>
      <p><?php echo basename($directory); ?></p>
   </td>
   <?php endforeach; ?>
</tr>

Do you not have access to this parameter in your current scope? Another option is:

<p><?php echo basename(pathinfo($img, PATHINFO_DIRNAME)); ?></p>

这篇关于如何回显目录名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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