|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12699 opendir() fails when used on read-only devices
Submitted: 2001-08-11 07:34 UTC Modified: 2001-10-02 18:38 UTC
From: Assigned:
Status: Closed Package: Directory function related
PHP Version: 4.0CVS-2001-08-11 OS: Win32
Private report: No CVE-ID: None
 [2001-08-11 07:34 UTC]
  <?php $dh = opendir('g:/'); ?>

gives me 

  Warning: OpenDir: Invalid argument (errno 22)

where g:/ is my CD Rom drive.

  <?php $dh = opendir('c:/'); ?>

works fine, c:/ beeing my harddrive.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-11 17:06 UTC]
Maybe when I change this to 'critical' someone notices :-)

 [2001-08-12 12:35 UTC]
do you have a CD in the drive when you run this script?
 [2001-08-12 12:39 UTC]
This is ridiculous. Of course I have a CD in the drive.

 [2001-08-12 12:58 UTC]

Just tested your code on my NT4 box with the 4.0.6 
release, and it works fine.

If you send me your php.exe and php4ts.dll buit from CVS 
I'll test that here if it helps.

 [2001-08-12 13:02 UTC]
Phil, I know that it worked fine with PHP 4.0.6. Have a look at the 'PHP Version' field
of this bug report. It says '4.0CVS-2001-08-11', which is yesterday's CVS version of 
PHP 4.0.7-dev.

 [2001-08-12 14:34 UTC]
Sorry Phil, I didn't read the 

    If you send me your php.exe and php4ts.dll buit 
    from CVS I'll test that here if it helps.

part of your message the first time.

I'm, really sorry! php.exe/php4ts.dll are on their way.

 [2001-08-12 15:03 UTC]
Just tested with the CVS binaries you sent me. It works 
fine accessing both my CD and DVD drives. If I echo out 
$dh, php prints
Resource id #1

For info, I'm running on NT4 SP6 under IIS, and my error 
reporting is set to E_ALL. I get the same results if I run 
from the command line.

 [2001-08-12 15:20 UTC]
It's not a permissions problem is it?
I sometimes have troubles with the CD rom drive under win2k, admittedly not from PHP/IIS but it could be related?

 [2001-08-12 15:31 UTC]
No, this shouldn't be the case here. The script worked fine until some 2-3 weeks ago.

 [2001-08-13 04:16 UTC]
Just updating with a couple of comments that were emailed 
rather than going via the bug tracking system:

Sebastian replied to the last bug posting:
 This is odd. The same binaries still give me with my CD
 and DVD drives
? Warning: OpenDir: Invalid argument (errno 22)
? <?php echo $dh = opendir('g:/'); ?>

To which Michael Loftis replied:
 g:\ is the windows way.... ?That could be whats
 fudging it.
 Justa ?wild guess.

And to which I now reply:

On NT and W2K G:/ is perfectly allright. Sebastian, what 
platform are you on (is it different from my NT4/IIS setup 
which seems to work ok?)

 [2001-08-13 04:31 UTC]
Okay, here's the news:

  <?php echo $dh = opendir('g:/'); ?>


  Resource id #1

when called from command-line with

  php -q opendir.php


  Warning: OpenDir: Invalid argument (errno 22)

when invoked through Apache/2.0.24-dev, where PHP is used as CGI.

Could this be a permissions issue after all? But, if so, why did it work some time ago?

Changing to 'Feedback'.

 [2001-08-13 05:23 UTC]
Just tested with Apache (version 1.3.12) on my NT box, and 
it's still ok.

It's a mystery to me what the permissions are on a read 
only device, however I would guess that since php is 
running in the same security environment, if it is a 
security issue, then you might find that Apache can't 
serve up files directly from the CD is you set up 
DocumentRoot to point to it.

 [2001-08-13 05:26 UTC]
Sorry - that last line should read:
*if* you set up 
DocumentRoot to point to it.

 [2001-10-02 18:38 UTC]
No feedback, considered fixed. (naughty, naughty Sebastian.. :)

 [2002-11-11 17:58 UTC] xenosis2000 at hotmail dot com
I ran into something similar with trying to OpenDir to a mapped network drive.

Variable Define:
$logpath = "s:\dir\System\";
Use it:
Warning: OpenDir: Invalid argument (errno 22) in logs.php on line 45
 [2002-11-11 17:59 UTC] xenosis2000 at hotmail dot com
By the way.. I still can't get it to work.. help appriciated.
 [2003-04-29 13:54 UTC] par at parwebworks dot net
Just noticed the topic is closed but...

It indeed is a security issue. On my server (win2k) I get the same error as the original author who has this problem. When using IIS (which I think he is), the IUSR_GUEST (wrong spelling but check your security rights on a directory it's something like that) needs read permissions on a folder for php to be allowed to access it. It's weird though that php generates this weird error rather than say "permission denied" which I would find a lot more obvious.. but then again, who would run IIS and php right?

When using my C:/inetpub/wwwroot as folder, the opendir works just fine and that has IUSR_guest access...

just fool around with those permissions and I'm sure you'll get it to work.
 [2003-04-29 14:47 UTC] par at parwebworks dot net
I changed the permissions in my inetpub directory to full access for the IUSR account (which I assume IIS uses for php to do file operations). Ofcourse full access is a bit much but, it works ;)

I'm not sure if this is the place for codes but figured I'd post my recursive files/directory reader function I wrote based on tons of "whatever is this supposed to work?" codes on the pages. Tried to add a comment there but all I got was a "" page not found error... so, if it's any useful, here it goes.. it's very basic and just gives a nice output of my full inetpub dir.



function rec_readdir($dirname)
  if ($dir = opendir($dirname))
    while (false !== ($file = readdir($dir)))
      if (($file !=='.') && ($file!=='..') && ($file !== $dirname))
        $checkdirname = $dirname."\\".$file;
          echo "<BLOCKQUOTE>\n";
          echo "<B>recdir: $checkdirname</B><BR>\n";
          echo "</BLOCKQUOTE>\n";
          echo "$dirname\<I>$file</I><BR>\n";

 [2003-12-09 14:55 UTC] matthias at rakplanet dot de
W2K + ISS + "openDir()"

i had the same problem with "openDir()" with W2K and ISS.
In attributes of the directory you want to open in the field "security adjustments" (sorry, im trying to translate it from German) there is a checkbox "take inheritable superior authorizations" (it is also a attempt to translate german text). I set this attribute and "openDir()" works fine.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 13:01:28 2024 UTC