0
<?php
$pathname = "http://myserver.com/projects/" . $_GET['project'] . "/";
if ($handle = opendir($pathname)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && (strpos($file, '.jpg',1)) ) {
$photo= $pathname . $file;
echo "<image src=\"" . $file . "\">";
}
}
closedir($handle);
}
?>
有我的代碼。我想要做的就是傳遞一個像「project = Flowers」這樣的URL參數,並讓PHP打開一個名爲/ flowers /的文件夾,並返回其中的所有.jpg圖像。使用OpenDir時出現URL文件訪問錯誤。爲什麼?
然而,當我跑我的代碼,我得到這些錯誤:
**警告:執行opendir()[function.opendir]:URL文件訪問是在服務器配置禁用 在 /NFS/C01/H03/MNT/73283 /域/ myserver.com/test.php的上 線3
警告:執行opendir(http://myserver.com/projects/flowers/) [function.opendir] :未能打開目錄:沒有合適的包裝可能是 在 /nfs/c05/h02/mnt/76383/domains/kulthous中找到e.com/html/staging/work.php on line 3 **
任何想法爲什麼這不起作用?
+1 ...沒有比這更清晰。 – RobB
所以我應該只使用相對路徑..?如果我的PHP腳本存在於完全不同的文件夾中,那麼opendir是從webserver根目錄開始的?或者我需要做「../../projects」嗎? – Ninjection
@Ninjection如果我是你,我會使用'$ _SERVER ['DOCUMENT_ROOT']'變量來標記文件系統路徑符合虛擬web服務器目錄系統的點。爲答案添加了代碼。 –