PHP readdir()和opendir()在本地工作,但不在实时服务器上工作


PHP readdir() and opendir() working locally but not working on live server

我得到了以下错误,所以更改了

opendir(http://test.myserv.com/Optfolder/upload/upload) 
[function.opendir]: failed to open dir: not implemented 

因此更改为file_get_contents($dir)

但接下来我得到了这个错误

readdir(): supplied argument is not a valid Directory resource 

我该怎么办?

我使用下面的代码来读取文件夹图像。有没有opendir和readdir的选项,所以我可以将它们用于我的目的?

在$dir中,我获得完整路径,如http://testserv.com/optfolder/upload

$dir = opendir($dir);
    while ($file = readdir($dir)) { 
       if (preg_match("/.png/",$file) || preg_match("/.jpg/",$file) || preg_match("/.gif/",$file) ) { 
       $string[] = $file;
       }
    }

opendir()不能在URL上使用,因为它打开了一个相对于文件系统的目录。这也是Warning:open-dir:未实现的潜在重复。

CCD_ 2在如何定位目录方面也与CCD_ 3完全相同。

请看一下文件http://php.net/manual/en/function.opendir.php以完全理解它。

您不能在HTTP URL上使用opendir()。您需要指定一个相对目录路径。请参阅opendir

尝试使用这个:

file_get_contents('http://testserv.com/optfolder/upload');