我遇到了这个问题。我写了这个PHP来输出指定文件夹中的子文件夹的内容。代码工作得很好,它显示了子文件夹中的所有图像。我遇到的问题是,在echo $underfolder
上,它只打印出第一个子文件夹而没有关闭DIV
class=image
。
怎么了?我疯了
<div class="folders">
<?php
global $current_user;
$current_user = wp_get_current_user();
$current_user_nambre = $current_user->user_login;
$sottocartelle = glob("wp-content/uploads/$current_user_nambre/*", GLOB_ONLYDIR);
foreach ($sottocartelle as $value) {
echo "<div class='products'>";
$underfolder = $value;
$contenuto = scandir($value);
echo $underfolder;
foreach ($contenuto as $value) {
echo "<div class='image;' style=\"display:inline-block;\">";
echo "<a href='/$underfolder/$value'>download</a>";
echo "<img src='/$underfolder/$value' height=\"100\height=\"100\" width=\"100\>";
echo '</div>';
}
echo '</div>';
}
?>
</div>
答案 0 :(得分:1)
检查img标记中的引号,并$value
重新分配$value
。在第二个foreach()
<div class="folders">
<?php
global $current_user;
$current_user = wp_get_current_user();
$current_user_nambre = $current_user->user_login;
$sottocartelle = glob( "wp-content/uploads/$current_user_nambre/*", GLOB_ONLYDIR );
foreach ( $sottocartelle as $value ) {
echo "<div class='products'>";
$contenuto = scandir( $value );
echo $value;
foreach ( $contenuto as $value1 ) {
echo '<div class="image;" style="display:inline-block;">';
echo "<a href='/$value/$value1'>download</a>";
echo "<img src='/$value/$value1' height='100' height='100' width='100'>";
echo '</div>';
}
echo '</div>';
}
?>
</div>
此代码应该可以正常工作。