2011-09-08 3 views
0

太字のファイルパスが機能しないようです。私はスクリプトがDir_3をスキャンするようにしたいと思います。どんな助けでも大歓迎です。PHP opendirを使って現在のディレクトリの外にあるディレクトリを読み込むには?

<?php 

    // These files will be ignored 
    $excludedFiles = array (
'excludeMe.file', 
'excludeMeAs.well' 
); 

// These file extensions will be ignored 
$excludedExtensions = array (
    'html', 
'xslt', 
'htm', 
'ahk', 
'xsl', 
'txt', 
'xml' 
); 

// Make sure we ignore . and .. 
$excludedFiles = array_merge($excludedFiles,array('.','..')); 

// Convert to lower case so we are not case-sensitive 
for ($i = 0; isset($excludedFiles[$i]); $i++) $excludedFiles[$i] =   
strtolower(ltrim($excludedFiles[$i],'.')); 
    for ($i = 0; isset($excludedExtensions[$i]); $i++) $excludedExtensions[$i] =  
strtolower($excludedExtensions[$i]); 

    // Loop through directory 
    $count = 0; 
    if ($handle = opendir('**http://www.mydomain.com/Dir_1/Dir_2/Dir_3/**')) { 
    while (false !== ($file = readdir($handle))) { 
    $extn = explode('.',$file); 
    $extn = array_pop($extn); 
    // Only echo links for files that don't match our rules 
    if (!in_array(strtolower($file),$excludedFiles) && 
    !in_array(strtolower($extn),$excludedExtensions)) { 
    $count++; 
    print("<a href=\"".$file."\">".$file."</a><br />\n"); 
    } 
} 
echo '<br /><br /><a href="..">Return</a>'; 
closedir($handle); 
} 

?> 

答えて

4

URLを 'opendir'することはできません。しかし、あなたはopendir関数内の相対パスと絶対パスを指定することができます。

opendir('.') // open current directory 
opendir('..') // open parent directory 
opendir('childdir') // open the 'childdir' directory which exists in the current directory (.) 
opendir('childdir/grandchilddir') // open a grandchild directory down two levels from the current dir 
opendir('../brotherdir') // open a directory next to the current one 
opendir('../brotherdir/nephewdir') // open a director next to and down one 
opendir('../..') // open a grandparent directory 
opendir('../../uncle') // yada yada yada 

opendir('/') // open the root dir (primordial slime/adam, depending on your viewpoint) 
opendir('/cain') // open a dir called "cain" which is housed in the root directory. 
+0

すごく助けてくれた素晴らしい。どうもありがとうございました。唯一の問題は、ページ上に吐き出されたリンクが適切にリンクしていないことです。私はそれが適切にリンクアップするために他の場所を調整する必要がありますか? – mikenichols

+0

Webベースのパスは、ファイルシステムのパスとはかなり異なる場合があります。 opendir()/ fopen()/ etc ...で動作するものは、これらのディレクトリがWebサイトにどのようにマップされているかとは全く関係がないかもしれません。 –

1

opendir()だけで、適切なファイルシステムのパスではなく、http://パスをサポートしています。

+0

あなたが使用することができ、他のサイトへのアクセスを持っている場合は、[FTP](http://php.net/manual/en/ref.ftp.php) – Xeoncross

関連する問題