0

私の質問には 2 つの部分があります。

1- ディレクトリD:/wamp/www/test/gmail-imap/upload/とそれに含まれる 5 つのファイルがあります。このディレクトリを次のように読み取る必要があります。

 ini_set('display_errors',1);
$dir = "D:/wamp/www/test/gmail-imap/upload/";
$i=0;
// Open a directory, and read its contents
if (is_dir($dir)){
  if ($dh = opendir($dir)){
   while (($file = readdir($dh)) !== false){

    if($file!=''){
     echo $i."-filename:" . $file . "<br>"; $i++;
    }
   }
  closedir($dh);
 }
}
die();

出力したのがこれ

 0-filename:.
 1-filename:..
 2-filename:1-stackoverflow.png
 3-filename:2-stackoverflow.png
 4-filename:3-Desert.jpg
 5-filename:4-code.zip
 6-filename:5-Chapter13.pdf

私の出力には 0 と 1 は必要ありません。

http://localhost/test/gmail-imap/uploads2-代わりにサーバーから読み取る必要がありますD:/wamp/www/test/gmail-imap/upload/

なにか提案を?

最初の部分は次のように修正されます

ini_set('display_errors',1);
$dir = "D:/wamp/www/test/gmail-imap/upload/";

// Open a directory, and read its contents
if (is_dir($dir)){
  if ($dh = opendir($dir)){
    if ($handle = opendir('.')) {
   while (false !== ($entry = readdir($handle))) {
    if ($entry != "." && $entry != "..") {
     echo "$entry\n";
    }
     }

 closedir($dh);
    }
  }
}
4

3 に答える 3

0
$file = "http://domain.com/directory/filename";
$save_path = 'download/';
$fp = fopen($save_path.basename($file), 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);

Curl で問題を解決できるかもしれませんが、どのファイルがダウンロードされるかを知る必要があります。

リモートディレクトリのリストが許可されている場合は、「 http://domain.com/directory 」などの URL から結果の html ページを解析し、ファイル名を見つけることができます...

于 2013-11-07T14:44:38.707 に答える