2014-03-02 4 views
0

내 폴더의 모든 항목을 나열하려는 다음 코드가 있습니다.하나의 주 도메인에서 다른 하위 도메인 제어

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

이 코드는 올바르게 작동합니다. 저는 현재 3 개의 다른 웹 사이트 (하위 도메인)에 대한 CMS를 만들고 있으며 주 도메인 (CMS)에서 모든 것을 제어하려고합니다. 어떤 식 으로든 $directory = "../img"$directory = "mysubdomain/img"으로 나열하고 데이터를 조작 할 수 있습니다.

+1

죄송합니다. 귀하가 요청한 내용이 확실하지 않습니다. – arkascha

+0

내가 www.mysite.com을 가지고 있고 $ directory = "../img"와 같은 img 폴더의 항목을 나열한다고 가정 해 보겠습니다. $ images = scandir ($ directory); 내 하위 도메인 subdomain.mysite.com의 img 폴더에있는 항목을 어떤 방법으로 나열 할 수 있습니까? $ directory = "subdomain.mysite.com/img"로 시도했습니다. $ images = scandir ($ directory); 하지만 작동하지 않습니다 – user2615859

+0

하위 도메인이 고정되어 있습니까? – anurupr

답변

0

모든 하위 도메인의 모든 img/디렉토리에있는 모든 파일을 나열하려면이 스크립트로 모두 스캔해야합니다.

이 코드에서와 같이 첫 번째 폴더의 경로는 "../img/"입니다.

/home/user/public_html/scripts/ 

을하고 이미지에있는 폴더 : 이것은에있는 스크립트를 나타낼 수

/home/user/public_html/img/ 

하지만 도메인이 어디에 있는지 우리는 알지 못한다. 두 개의 하위 도메인의 알파와 베타가있는 경우 IMG/폴더는 다음 위치에있을 수 있습니다

/home/user/public_html/alpha/img/ 
/home/user/public_html/beta/img/ 

그런 경우는 다음의 경우 두 개 더 scandirs 실행해야합니다 :

scandir('../alpha/img/'); 
scandir('../beta/img/'); 

을 또는 당신에게 디렉토리를 변경 to :

$directory = "../img"; 
/* save result */ 
$directory = "../alpha/img"; 
/* save result */ 
$directory = "../beta/img"; 
/* save result */ 
/* Show all three results somehow to user */ 

적어도 알파와 베타를 하위 도메인의 하위 디렉토리 이름으로 변경해야합니다. 기껏해야 서버의 파일 경로를 찾아야합니다.

+0

덕분에 나는 다시 돌아올 것이다. – user2615859

관련 문제