0

我想在其 DIV 标记内的图像“folderContents05.jpg”顶部显示文件夹内容。PHP 脚本应该输出它所在目录的文件夹内容。脚本本身可以正常工作,但是当我在 html 中使用它或调用脚本时,我似乎无法显示任何内容。

这是HTML-

<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
<!-- End Save for Web Styles -->
</head>
<body style="background-color:#353535; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px;">
<!-- Save for Web Slices (index.psd) -->
<div id="wrapper">
<div id="Table_01">
<div id="folderContents01">
<img src="images/folderContents01.jpg" width="359" height="120" alt="">
</div>
<div id="folderContents02">
<img src="images/folderContents02.jpg" width="591" height="150" alt="">
</div>
<div id="folderContents03">
<img src="images/folderContents03.jpg" width="359" height="30" alt="">
</div>
<div id="folderContents04">
<img src="images/folderContents04.jpg" width="126" height="460" alt="">
</div>
<div id="folderContents05">
<img src="images/folderContents05.jpg" width="698" height="396" alt="">
</div>
<div id="folderContents06">
<img src="images/folderContents06.jpg" width="126" height="460" alt="">
</div>
<div id="folderContents07">
<img src="images/folderContents07.jpg" width="698" height="64" alt="">
</div>
<div id="folderContents08">
<img src="images/folderContents08.jpg" width="950" height="90" alt="">
</div>
</div>
</div>
<!-- End Save for Web Slices -->
</body>
</html>

和php脚本

<?php
$count = 0;
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {$count++;
print("<a href=\"".$file."\">".$file."</a><br />\n");
}
}
closedir($handle);
}
?>
4

3 回答 3

0

这是你想要的吗?

<div id="folderContents05" style="position: relative">
  <img src="images/folderContents05.jpg" width="698" height="396" alt="">
  <div style="position: absolute; left: 0; top: 0; z-index: 100">
  <?php
   $count = 0;
   if ($handle = opendir('.')) {
     while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
         $count++;
         print("<a href=\"".$file."\">".$file."</a><br />\n");
       }
     }
   closedir($handle);
   }
  ?>
  </div>
</div>
于 2012-08-26T16:25:21.290 回答
0

您必须将“文件夹内容”图像作为 div 的背景,并通过 php 本身生成 HTML 标记,类似于下面的代码

if ($file != "." && $file != "..") {$count++;
print(<div id="folderContents +i">
</div>)

并放置一个计数器,以便您可以使用它来生成(folderContents1、folderContents2 等)。

于 2012-08-26T16:11:20.847 回答
0

style= "z-index: 0"在您的标签上使用<img>并将 PHP 更改为:

<?php
$count = 0;
if ($handle = opendir('.')) {
echo '<div style="z-index: 1">';
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {$count++;
print("<a href=\"".$file."\">".$file."</a><br />\n");
}
}
echo '</div>';
closedir($handle);
}
?>

使用 z-index 为元素建立“在顶”的顺序

于 2012-08-26T16:23:19.880 回答