我的问题有两个部分。
1-我有目录D:/wamp/www/test/gmail-imap/upload/,它包含五个文件。我必须将这个目录读作
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我的output.Am中不需要0和1我是否遗漏了什么?
2-我必须从服务器http://localhost/test/gmail-imap/uploads而不是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);
}
}
}发布于 2013-11-07 22:31:17
对于点1)
看一看scandir函数。它将结果放入一个数组中。知道数组中的位置0和1几乎总是。然后..。你可以把它们排除在外
对于点2)
我真的不明白你的意思。看起来你想下载这些文件,但是从localhost下载是没有意义的。使用路径D:/...有什么问题?
请详细说明这一点,我看看是否可以提供一个答案。
发布于 2013-11-07 22:44:39
$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也许可以解决您的问题,但是您需要知道将下载哪些文件。
如果远程目录列表是允许的,您可以解析结果html页面从一个网址,如"http://domain.com/directory“,并找到文件名...
https://stackoverflow.com/questions/19838288
复制相似问题