PHP函数is_writeable非常奇怪的行为。

cutemouse 2006-08-25 12:43:34
我写的PHP代码如下:testfile.php

<?php
$writeok = array("uploads/", "cache/", "templates_c/", "mainfile.php");
$title = "test file php";
$content = "<table align='center'><tr><td align='left'>\n";
$error = false;
foreach ($writeok as $wok) {
echo "<br />"."../".$wok."<br />";
echo fileowner("../".$wok)."<br />";
echo filegroup("../".$wok)."<br />";
echo fileowner("../".$wok)."<br />";
echo substr(sprintf('%o', fileperms("../".$wok)), -4)."<br />";
echo filetype("../".$wok)."<br />";

if (!is_dir("../".$wok)) {


if ( file_exists("../".$wok) ) {
@chgrp("../".$wok, fileowner("../".$wok));
@chmod("../".$wok, 0666);
if (is_writeable("../".$wok)==false) {
$content .= "file ".$wok." is not writeable"."<br />";
$error = true;

}else{
$content .= "file ".$wok." is writeable"."<br />";
}
if (!is_readable("../".$wok)) {
$content .= "file ".$wok." is not readable"."<br />";
$error = true;

}else{
$content .= "file ".$wok." is readable"."<br />";
}

}
} else {
@chgrp("../".$wok, fileowner("../".$wok));
@chmod("../".$wok, 0777);
if (!is_writeable("../".$wok)) {
$content .= "dir ".$wok." is not writeable"."<br />";
$error = true;

}else{
$content .= "dir ".$wok."is writeable"."<br />";
}
if (!is_readable("../".$wok)) {
$content .= "dir ".$wok." is not readable"."<br />";
$error = true;

}else{
$content .= "dir ".$wok." is readable"."<br />";
}
}
}
$content .= "</td></tr></table>\n";

if(! $error) {
$content .= "<p>"."not error"."</p>";


}else{
$content .= "<p>"." error "."</p>";

}

echo $content;

?>



可是执行结果非常奇怪:

../uploads/
0
0
0
0777
dir

../cache/
0
0
0
0777
dir

../templates_c/
0
0
0
0777
dir

../mainfile.php
0
0
0
0666
file
dir uploads/ is not writeable
dir uploads/ is readable
dir cache/ is not writeable
dir cache/ is readable
dir templates_c/ is not writeable
dir templates_c/ is readable
file mainfile.php is not writeable
file mainfile.php is readable



error

到底是什么原因?

...全文
275 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
cutemouse 2006-08-25
  • 打赏
  • 举报
回复
楼上的说法,我也看过,'nobody'或其他的webserver的用户名好像没有.
xuzuning 2006-08-25
  • 打赏
  • 举报
回复
记住 PHP 也许只能以运行 webserver 的用户名(通常为 'nobody')来访问文件。不计入安全模式的限制。

注: 本函数的结果会被缓存。更多信息参见 clearstatcache()。

代码下载链接: https://pan.quark.cn/s/a175d1ef418b 标题部分中的"新建文件夹 (2).zip"暗示这是一个采用ZIP编码方式的压缩文档,这种格式通常用于将多个关联的文件或目录整合进一个压缩单元中。在信息技术领域,ZIP编码格式是一种广泛应用的标准,它支持将多个数据单元压缩成一个独立的压缩文件,从而提升文件传输的便捷性、存储空间的利用效率以及管理的便捷度。ZIP格式的压缩文件可以通过多种解压缩工具进行访问,例如WinRAR软件、7-Zip应用程序或操作系统自带的压缩解压功能。 描述文本里的"shop"字样或许指向这个压缩文档与商业店铺、电子商务平台或网络销售系统存在关联。在Java编程范畴内,这有可能是一个范例项目,用以说明构建电子商务平台相关功能的实现方法,涵盖商品维护、购物车功能以及订单处理等模块。Java语言因其跨平台兼容性、系统稳定性以及完备的库资源支持,经常被选作开发大型企业级应用的技术栈,尤其是电子商务系统。 依据标签"java"的指示,可以推断压缩包内部可能包含了采用Java编程语言编写的源代码片段、系统配置文档、数据库操作脚本及其他辅助性资源。Java程序员一般借助集成开发环境(IDE)如Eclipse、IntelliJ IDEA或NetBeans进行Java代码的编写、编译及执行操作。这些开发工具能够高效地支持ZIP文件中项目结构的导入与管理。 文件命名列表仅列出一个条目"新建文件夹 (2)",这或许意味着压缩文档中包含一个同名的文件夹,该文件夹内可能收纳了一系列子文件及子目录。在实际的Java开发任务中,类似的结构可能包含src目录(存放程序源代码)、lib目录(存放项目依赖的jar库文件)、resou...

21,889

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧