0

When using following code:

if ($handle = opendir('../flat')) {

}

I'm getting this error:

Warning: opendir(../flat) [function.opendir]: failed to open dir: No such file or directory in D:\Inetpub\webs\mysite\newSite\lib\flat.php on line 1

Using

dirname(__FILE__);

I can see the correct path of my PHP script:

D:\Inetpub\webs\mysite\newSite\lib

Using absolute path opendir works good:

if ($handle = opendir('D:\Inetpub\webs\mysite\newSite\flat')) {

}

What could be the problem? Can someone help me?

jvdhooft
  • 657
  • 1
  • 12
  • 33
Jayyrus
  • 12,961
  • 41
  • 132
  • 214
  • Use a path explicitly relative to the script directory: `dirname(__FILE__) . DIRECTORY_SEPARATOR . '../flat'`. – DCoder Jul 08 '12 at 06:46

1 Answers1

-2

PHP's open dir functions don't work with URLs, unless they're full and absolute. Your relative path will not work with open dir unless it is a file directory or absolute path like http://www.example.com/blah/blah..

According to the PHP manual:

a) path supports the ftp:// URL wrapper.

b) path can also be any URL which supports directory listing, however only the file:// URL wrapper supports this in PHP 4

Vlad
  • 18,195
  • 4
  • 41
  • 71