PHP:为什么 readdir 在命令行上对我有用,但在浏览器上却不起作用?
我有 2 个文件夹: /var/www/vhosts/mydomain.com/httpdocs/ 和 /var/www/vhosts/mydomain.com/httpdocs/duh/
两个文件夹具有完全相同的权限、组、所有者等一切。
如果我将 $path 设置为第一个,没有问题,我会回显文件名中带有“html”的文件列表。
如果我将 $path 设置为第二个,它就会在 opendir() 上消失。然而,它在命令行上工作得很好,只是在浏览器上不行。
有什么想法吗?
这是我的非常简单的代码:
<?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;
}
}
?>
I have 2 folders:
/var/www/vhosts/mydomain.com/httpdocs/
and
/var/www/vhosts/mydomain.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;
}
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
duh
文件夹的权限是什么?请记住,网络服务器将在与您的 shell 帐户不同的用户 ID 下运行。确保目录的模式为 0755,以便所有用户都可以读取。哎呀,只是您对错误消息的评论。所以,是的,权限错误。
duh
由用户 ID 10012 拥有,而您的 Web 服务器以 root 身份运行。安全模式不允许这样做。 'chown' root 拥有的目录...当然,为什么网络服务器以 root 身份运行?这是非常没有安全感的。
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.
现在你知道答案了:它的 SAFE_MODE,最丑陋的 PHP 功能之一。
有一些解决方法,但最好的方法是尽快从该主机运行!
或者找到一种方法来禁用它。
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.
我想通了。我正在使用的服务器具有每个虚拟主机的本地配置文件。本地conf的safe_mode设置为on。
感谢那些引导我走上这条路的人。
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.