1
我已經做了一個php圖片庫,它應該列出「圖片」文件夾的所有子目錄,並單擊時,顯示該文件夾中的第一個圖像與以前的鏈接和下一張照片。當它列出第20行上的「圖片」文件夾的子目錄時,不會返回任何內容。另外,下一個和上一個鏈接始終顯示指向相冊頁面的鏈接,而不是下一個圖像。PHP opendir()不打開子目錄
我做錯了什麼?我的代碼的任何批評也將讚賞。
<?
//Return the contents of a folder which are images as an array
function dirContents($folder){
if ($handle = opendir($folder)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !is_dir($file) && (pathinfo($file,PATHINFO_EXTENSION) == 'jpg')) {
$contents[] = $file;
echo "$file</br>";
}
}
closedir($handle);
}
return $contents;
}
if (!isset($_GET['album'])){
//List all the albums from the pics folder
echo '<div class="subhead">Albums</div>';
echo '<ul>';
if ($handle = opendir("./pics")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && is_dir($file)) {
echo '<li><a href="?page=gallery&album='.$file.'&i=0">'. $file. '</a></li>';
}
}
echo '</ul>';
closedir($handle);
}
}
else{
// Include some input validation here to see if $album is actually a subfolder of pics
$album = $_GET['album'];
if (!isset($_GET['i']))
$i = 0;
else
$i = $_GET['i'];
$ip = $i-1;
$in = $i+1;
$images = dirContents($album);
$len = count($images);
echo "<div class=\"subhead\">$album, Num photos = $len</div>";
echo '<div class="viewer">';
if ($ip < 0)
echo '<a href="?page=gallery">Albums</a>';
else
echo "<a href=\"?page=gallery&album=$album&$ip\">Albums</a>";
echo "<img src=\"$album\\$images[$i]\" />";
if ($in >= count($album))
echo '<a href="?page=gallery">Albums</a>';
else
echo "<a href=\"?page=gallery&album=$album&$in\">Next</a>";
echo '</div>';
}
echo 'All images appear here with the given consent of those persons that appear within them';
?>
您可以通過執行獲得當前文件的目錄`目錄名(__ FILE __)`(或`__DIR__`如果您使用5.3+) – 2010-12-10 04:31:53