簡體   English   中英

列出同一服務器上另一個域的文件夾內容

[英]listing the folder content of another domain on the same server

我在服務器上有2個域。 假設domain1.com和domain2.com我想在domain1.com上列出文件夾domain2.com/images的內容。 我嘗試了以下代碼。

$directory  = "domain2.com/images"; 
$images = scandir($directory);
$ignore = Array(".", "..");
$count=$count;
echo "<table border=0 style='float:left;margin-left:115px;'>";
foreach($images as $dispimage){
if(!in_array($dispimage, $ignore)){
echo "<tr id='del_pl$count'><td>$count</td><td style='width:300px;'><a href='$directory/$dispimage' target='_blank'>../img/img_large/$dispimage</a></td><td><input type='button' style='padding:0;height:17px;' id='delete$count' value='Delete' onclick='deleteFile(\"$dispimage\",$count,\"$directory\",\"pl\");'></td></tr>";
$count++;
}
}

它不起作用,可能是我需要分配某種權利來執行此操作,還是問題出在其他地方。 僅作為參考,如果我使用domain1或domain1本身的子域,則代碼運行良好。

讓我們假設您以這種方式在服務器中擁有文件夾結構:

- www/
|- domain1.com/
|  |- hello.htm
|  |- image.png
|  |- photo.jpg
|  |- graph.svg
|  |- tasks.txt
|- domain2.com/
|  |- css/
|  |  |- style.css
|  |- js/
|  |  |- scripts.js
|  |- index.php
- cgi-bin

而且,如果您想從domain2.comindex.php文件中列出domain1.com的內容,則可以使用以下命令訪問文件夾結構:

$directory = "../domain1.com";
$images = readdir(opendir($directory));
$ignore = Array(".", "..");
$count = 1;
echo "<table border=0 style='float:left;margin-left:115px;'>";
foreach ($images as $dispimage) {
  if (!in_array($dispimage, $ignore)){
    echo "<tr id='del_pl$count'><td>$count</td><td style='width:300px;'><a href='$directory/$dispimage' target='_blank'>../img/img_large/$dispimage</a></td><td><input type='button' style='padding:0;height:17px;' id='delete$count' value='Delete' onclick='deleteFile(\"$dispimage\",$count,\"$directory\",\"pl\");'></td></tr>";
    $count++;
  }
}
echo "</table>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM