开发者

PHP: Why is readdir working for me at command line but not browser?

开发者 https://www.devze.com 2023-01-13 13:18 出处:网络
I have 2 folders: /var/www/vhosts/mydomain.com/httpdocs/ and /var/www/vhosts/mydomai开发者_JAVA百科n.com/httpdocs/duh/

I have 2 folders: /var/www/vhosts/mydomain.com/httpdocs/ and /var/www/vhosts/mydomai开发者_JAVA百科n.com/httpdocs/duh/

Both folders have the EXACT same perms, group, owner, everything.

If I set $path to the first one, no problems, I echo a list of files with 'html' in the filename.

If I set $path to the second one, it dies on the opendir(). However, it works fine from the command line, just not the browser.

Any ideas?

Here's my very simple code:

<?php
        $path = "/var/www/vhosts/mydomain.com/httpdocs/duh/";

        $img_folder = opendir($path) or die("Unable to open $path");

         while (false !== ($file = readdir($img_folder))){
             if (eregi("html", $file)){
                echo $file;
             }
         }
    ?>


What are the permissions on the duh folder? Remember that the webserver will be running under a different user ID than your shell account. Make sure the dir's mode 0755 so it's readable by all users.

oops, just your comment with the error message. So, yes, permissions error. duh is owned by user id 10012, while your web server's running as root. safe mode will not allow this. 'chown' the directory to be owned by root...

Of course, why is the webserver running as root? That's horribly insecure.


Well now you know the answer: its SAFE_MODE, one of the ugliest PHP features.
There are some workarounds, but the best of them is run from this host as fast as you can!
or find a way to disable it.


I figured it out. The server that I'm working on has local config files for each vhost. safe_mode was set to on for the local conf.

Thanks to those that led me down the path.

0

精彩评论

暂无评论...
验证码 换一张
取 消