I have code as below:

$dir = opendir("D:/Marcin");
if ($dir) {
echo "OK";
}
else {
echo "not ok";
}

and I get not ok, why??

有帮助吗?

解决方案

I believe you are trying to open a directory server-side. If you were doing so locally, it would work - as I can see that you are getting the directory from your PC, but instead, you are attempting to execute the script in the client-side, and getting a server-side result.

This means that if that directory doesn't exist on your server, the server will not be able to find the file - and will return false.

At a certain point, you must check whether the directory exists on your server.

localserver === local directory = true;
webserver === web directory = true;

If both of the two are cross-referenced, it will return to false.

$dir = opendir("D:/Marcin"); // Check whether the directory exists on your server.
if ($dir) {
    echo "OK";
} else {
    echo "Not OK";
}

Hope this assists.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top