如何使用PHP读取远程服务器上的目录内容? [英] How can I read the directory contents on a remote server with PHP?
本文介绍了如何使用PHP读取远程服务器上的目录内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网址, http://www.mysite.com/images
和图像
目录允许目录列表如何使用PHP获取该目录中的文件?
I have a url, http://www.mysite.com/images
and the images
directory allows Directory Listings. How can I get the files in that directory with PHP?
推荐答案
如果您需要通过HTTP而服务器是Apache:
Here is an example if you need to read the images over HTTP and the server is Apache:
<?php
$url = 'http://www.mysite.com/images';
$html = file_get_contents($url);
$count = preg_match_all('/<td><a href="([^"]+)">[^<]*<\/a><\/td>/i', $html, $files);
for ($i = 0; $i < $count; ++$i) {
echo "File: " . $files[1][$i] . "<br />\n";
}
?>
如果是运行PHP的同一个服务器,可以使用opendir()和readdir()。
If it is the same server you are running your PHP on, you can use opendir() and readdir().
这篇关于如何使用PHP读取远程服务器上的目录内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文