php 警告:打开目录:未实现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12018003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: open dir: not implemented
提问by Geert
I'm new to PHP, and I'm trying to build a script. When I load the script, I get the following error:
我是 PHP 新手,正在尝试构建脚本。当我加载脚本时,出现以下错误:
Warning: opendir(http://www.hetweerinboskamp.nl/voorpagina/movies) [function.opendir]: failed to open dir: not implemented
警告:opendir(http://www.hetweerinboskamp.nl/voorpagina/movies) [function.opendir]:打开目录失败:未实现
<?php
$hal ='';
$dir ='http://www.hetweerinboskamp.nl/voorpagina/movies';
if ($handle = opendir($dir)) {
// Loop the folders
while (false !== ($file = readdir($handle))) {
if(strlen($file) > 4) {
$rawd = parsename($file);
$hal.= 'new Date('.substr($rawd,0,4).', '.substr($rawd,4,2).'-1, '.substr($rawd,6,2).'),';
//$hal.= $rawd.',';
}
closedir($handle);
}
采纳答案by Adam Zalcman
opendir()is used to open a local directory and since PHP 5.0.0 on an ftp directory.
opendir()用于打开本地目录,并且自 PHP 5.0.0 起在 ftp 目录上。
If your PHP code runs on www.hetweerinboskamp.nl then /voorpagina/moviesis actually a local directory and you can do this:
如果您的 PHP 代码在 www.hetweerinboskamp.nl 上运行,那么/voorpagina/movies它实际上是一个本地目录,您可以这样做:
$dir ='<wwwroot>/voorpagina/movies';
if ($handle = opendir($dir)) {
where wwwrootis the root of the filesystem as seen by your php code.
wwwroot你的php代码看到的文件系统的根在哪里。
If you're trying to download content from another website, try e.g. file_get_contents(). Note that if the remote server lists the content of a directory the listing is in fact an HTML page generated on the fly by the server. You may find yourself needing to parse that page. A better approach is to check whether the server offers some sort of API where it sends back the content in a standardized form, e.g. in JSON format.
如果您尝试从其他网站下载内容,请尝试例如file_get_contents()。请注意,如果远程服务器列出目录的内容,则该列表实际上是服务器动态生成的 HTML 页面。您可能会发现自己需要解析该页面。更好的方法是检查服务器是否提供某种 API,在该 API 中它以标准化形式(例如 JSON 格式)发回内容。
回答by Quentin
opendiroperates on directories on a filesystem, not HTTP URIs.
opendir操作文件系统上的目录,而不是 HTTP URI。
While some HTTP URIs return directory listings (the one you are using doesn't, it is a 404 error), those listings as HTML documents generated by the webserver and are not actual directories.
虽然一些 HTTP URI 返回目录列表(您使用的那个不返回,这是一个 404 错误),但这些列表是由网络服务器生成的 HTML 文档,而不是实际目录。
回答by Sammaye
Most remote servers does not send a directory listing back as such opendir cannot understand what your trying to do so it cant work.
大多数远程服务器不会发回目录列表,因为 opendir 无法理解您尝试执行的操作,因此无法正常工作。
You will need to use something like ftp, here is an example: http://php.net/manual/en/ftp.examples-basic.phpor cURL
你需要使用类似 ftp 的东西,这里是一个例子:http: //php.net/manual/en/ftp.examples-basic.php或 cURL
回答by M.Z.
Manual claims this function works with URL's, however, it appears it doesn't.
手册声称此功能适用于 URL,但是,它似乎没有。
Use a local path (either relative or absolute). For example, './voorpagina/movies'. This has solved a similar problem to me before. I hope this helps.
使用本地路径(相对或绝对)。例如,'./voorpagina/movies'。这已经解决了我以前的类似问题。我希望这有帮助。

