Q:

listing the folder content of another domain on the same server

I have 2 domains on the server. Let say domain1.com and domain2.com I want to list the content of a folder domain2.com/images on domain1.com. I have tried with the following piece of code.
$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++;
}
}

It is not working, can it be that i need to assign some kind of right to do this or the problems is somewhere else. Just for the information, the code is working well if I am working with the subdomains of the domain1 or domain1 itself.

A:

Let us assume that you have your folder structure in the server this way:
- 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

And if you would like to list out the contents of the domain1.com from domain2.com's index.php file, you can access the folder structure using:
$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>";

