在php中的图像下方显示图像名称

时间:2017-02-23 04:16:05

标签: php css opendir

这是我用来制作图库类型的代码:

主要PHP:

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
          <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
          <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
           <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
           <style type="text/css">
            
           </style>
           </head>
           <body>
            <div class="container">
    <div class="row">
        <label For="something" class="col-sm-2 form-label">Somethingwefwef</label>
        <input class="col-sm-10" name="something" type="text"  class="form-control" />
    </div>
</div>
  </body>
  </html>

我该怎么做才能显示所有图像名称。请帮忙。

2 个答案:

答案 0 :(得分:2)

while循环中尝试此操作:

$file_path = $folder_path.$file;
$path_parts = pathinfo($file_path);
$extension = strtolower($path_parts['extension']);
if($extension=='jpg' || $extension =='png' || $extension == 'gif' || $extension == 'bmp')
{
    echo '<a href="'.$file_path.'"><img src="'.$file_path.'" height="200" />'.$path_parts['filename'].'</a>';
}

答案 1 :(得分:1)

检查此行:

$file_path = $folder_path.$file;

此处$file是文件的名称,您可以使用它来显示文件名,如:

echo $file;

根据您的要求,它就像:

<a href="<?php echo $file_path; ?>"><img src="<?php echo $file_path; ?>"
<?php echo $file; ?>