Click to See Complete Forum and Search --> : Help with php.ini, please...


msmith29063
04-07-2003, 12:26 PM
I'm using a script that allows users to upload files to a folder using the opendir() function. But I encounter this error when displaying the page:

"PHP Warning: opendir(docs) [function.opendir]: failed to open dir: Invalid argument in D:\WEBS\Mainspring\clients\carealliance\document.php on line 72 PHP Warning: readdir(): supplied argument is not a valid Directory resource in D:\WEBS\Mainspring\clients\carealliance\document.php on line 73 PHP Warning: closedir(): supplied argument is not a valid Directory resource in D:\WEBS\Mainspring\clients\carealliance\document.php on line 81"

Does this look like a php.ini configuration issue? I recently had someone install PHP on this Windows server. What should I look for?

I've posted the php.ini file for review, here (http://www.mathewsmithstudio.com/php/php.ini).

Thank you for any help.

ognotongo
04-07-2003, 03:51 PM
It sounds like you aren't opening the directory before you read from it. You need to do something like the following:



<?php
if ($dir = @opendir("/tmp")) {
while (($file = readdir($dir)) !== false) {
echo "$file\n";
}
closedir($dir);
}
?>
//from php.net website



Basically you need to open the directory first, when you do this you are passed a handle to the directory. You then pass this handle to readdir(), closedir(), etc....

msmith29063
04-07-2003, 09:15 PM
Here's the code. Keep in mind that register_globals is set to "off" in my php.ini file.

I know this code works. I use it on my Unix-hosted websites.

// Read the files from the directory

$Open = opendir("docs");

while ($Files = readdir($Open)) {

$Filename = "docs/" . $Files;

if (is_file($Filename)) {

$Size = filesize("docs/$Files");

$Show_Filesize = number_format($Size/1024) . " KB";

print ("<TR><TD class=small><a href=\"docs/$Files\">$Files</a></TD><TD class=small>$Show_Filesize</TD><TD class=small><INPUT TYPE=CHECKBOX NAME=\"Delete[]\" VALUE=\"$Files\"></TD><TD class=small><INPUT TYPE=CHECKBOX NAME=\"Rename[]\" VALUE=\"$Files\"> <INPUT TYPE=TEXT NAME=\"NewName[$Files]\"></TD></TR>\n");

}

}

closedir($Open);

ognotongo
04-08-2003, 12:36 PM
Sorry, I didn't catch the first error in your output. For whatever reason your opendir call is failing (sorry for pointing out the obvious). I took a scan through your php.ini file and everything looked fine.

I would first start with the permissions on the directory your trying to read. Make sure that the user you web server is running as has permission to access that directory.

From there I would try changing the value you are passing to opendir(). I tried a little test and found that if my script is in "c:\apache\htdocs\temp\script.php", I needed to pass "../temp" to read the directory the script is located in. When I just passed "temp" to the opendir call I got the same errors you did. Hope this helps.